LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get SetEndOfFile (or anything in kernel32.lib) to link

Solved!
Go to solution

I'm attempting to truncate a file using the SDK function SetEndOfFile. I'm essentially trying to recreate the code that RobertoBozzolo posted in this thread. I'm using CVI 2015 and the 8.1 SDK.

 

I consulted Microsoft's SetEndOfFile documentation and saw that I needed to include fileapi.h, so I did that. According to that page, and the CVI "Availability of SDK" Help topic, SetEndOfFile is contained in kernel32.lib. I added that library to my project and then attempted to build. Unfortunately I started getting link errors:

 

error: Undefined symbol '_SetEndOfFile' referenced   (along with Undefined symbols for _CreateFileA and _GetLastError)

 

All of those functions should be in kernel32.lib. The CVI help topic also lists those functions as being in mincore.lib so I tried adding that to my project. Still no luck, with both mincore and kernel32.lib or only mincore.lib. It seems like anything that's supposed to be available in kernel32.lib doesn't work.

 

So then I decided to try and add EVERY lib in "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86"... all 450 of them. After CVI froze for a good 20 seconds, all the libs were added and still those symbols were undefined.

 

I'm not entirely a stranger to using SDK libs. This exact same project is successfully using a bunch of functions from WinInet.lib without issue, from the exact same path. I feel like I'm probably doing something stupid, but I can't figure out what it is.

Kevin B.
0 Kudos
Message 1 of 3
(3,818 Views)
Solution
Accepted by topic author Kevin_B.

Figured it out. It was an include order issue, related to toolbox. This order didn't work:

 

#include <fileapi.h>
#include <Windows.h>
#include <toolbox.h>

But this one linked and ran perfectly:

 

#include <Windows.h>
#include <toolbox.h>
#include <fileapi.h>
Kevin B.
0 Kudos
Message 2 of 3
(3,808 Views)

Yes, as a general rule Windows.h, as all others include files related to WIN32 API, should be #included before all other includes. A guidance on this subject can be found here.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 3
(3,783 Views)