I am using CreateProcess to invoke cl and link to compile and link another C++ program (TestProg.cxx) into a DLL. I found the correct compilation and linkage options:
Compilation Options:
/W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _WINDOWS /D _USRDLL /D BUILDDLL_EXPORTS /D _WINDLL /D _UNICODE /D UNICODE /GS /fp:precise /Zc:wchar_t /Zc:forScope /Gd /analyze- /errorReport:queue /LD
Linkage Options:
/INCREMENTAL /NOLOGO "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /ERRORREPORT:QUEUE /Entry:DllMain
I call CreateProcess with:
if ( CreateProcess(full path to cl.exe, compilation options, NULL,NULL,FALSE,0, NULL,NULL,&si,&pi) )
{
//....
}
Running the application from VS tools prompt, it works and the dll is created.
But running it from the VS debugger I get the following LINK error:
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
or when the link libs are removed from the link options I get the following error:
LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'
What am I doing wrong?
IMO it seems something is missing in the link options to run in debug mode, or the search path of debug mode lacks some directories. I don’t know how to fix any of these cases.
I googled this for the last 1/2 day, but didn’t find it. Using windows API is new to me.
Many thanks in advance
Sounds like you’re missing the environment variables which you get when running from the VS command line.
Part of this is also the library search path.
See
C:\Program Files\Microsoft Visual Studio XX\Common7\vsvars32.bat(depending on your VS version and installation path, which is specified in theVS100COMNTOOLS(orVS90COMNTOOLS, or which ever) environment variable.Why are you doing this anyway? You could be using MSBuild to configure a project and build it. You can call MSBuild from your code, while the project is already configured for you.