I tried to use CxImage in my project VC++, however I use a walkthrough for create static libs and link with a project in VC++ 2010.
Everything looks fine when I generate the project that link the cximage.lib, but for some reason when I use certain functions the compiler threw me a LINK:2001 unresolved external symbol.
This is the first time I work with visual static libraries, if someone have the solution or a suggestion for this I would be grateful.
here is my code:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
CxImage imag;
imag.Save((const TCHAR *)"hola.bmp",CXIMAGE_FORMAT_BMP);
return 0;
}
and there it is, CxImage is recognized by the compiler but some functions on the linker not. In this case the function Save, if I used other functions and work, the generation is successful. I searched over the net and find that I could by not including a library but I include it.
The link error is the next:
pruebaCxImage.obj : error LNK2001: sÃmbolo externo "public: bool __thiscall CxImage::Save(wchar_t const *,unsigned int)" (?Save#CxImage##QAE_NPB_WI#Z) sin resolver
for more information this is the command's of my linker in the project:
/OUT:"C:\Documents and Settings\diego\Mis documentos\Visual Studio 2008\Projects\pruebaCxImage\Release\pruebaCxImage.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"Release\pruebaCxImage.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Documents and Settings\diego\Mis documentos\Visual Studio 2008\Projects\pruebaCxImage\Release\pruebaCxImage.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "..\..\..\..\..\escritorio\cximage701_full\cximage\release\cximage.lib"
You build the exe with UNICODE/_UNICODE defined, since TCHAR expands to wchar_t (see the linker error), so my guess is that you built the lib without defining UNICODE/_UNICODE or didn't add the lib output directory to the list of lib input directories in the exe properties.
Related
I need to analyze exactly how MSBuild builds a C++ project, in order to rebuild it in a different way with a different toolchain. At the moment, my main strategy for doing this is to run msbuild -fl to ask it to log its actions, then I can try to analyze the resulting msbuild.log. The compile steps in this seem clear enough, but I am still trying to figure out the linking steps.
When I use Visual Studio 2022 to create a skeleton console application, the linking step is recorded in msbuild.log as
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\HostX64\x64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\olivine\test\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe" /INCREMENTAL /ILK:"x64\Debug\ConsoleApplication1.ilk" /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 /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\olivine\test\ConsoleApplication1\x64\Debug\ConsoleApplication1.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\olivine\test\ConsoleApplication1\x64\Debug\ConsoleApplication1.lib" /MACHINE:X64 /pdbthreads:4 x64\Debug\ConsoleApplication1.obj
that is, a lot of options, plus the name of the object file (the skeleton project only has one object file). That seems straightforward.
Now trying the same thing again on a skeleton desktop application:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\HostX64\x64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\olivine\test\Project1\x64\Debug\Project1.exe" /INCREMENTAL /ILK:"x64\Debug\Project1.ilk" /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 /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\olivine\test\Project1\x64\Debug\Project1.pdb" /SUBSYSTEM:WINDOWS /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\olivine\test\Project1\x64\Debug\Project1.lib" /MACHINE:X64 /pdbthreads:4 x64\Debug\Project1.res
x64\Debug\Project1.obj
Again, the skeleton project only has one object file. This time, it is not placed at the end of the link command, but on a separate line after the link command. Inspection of msbuild.log for a real project suggests this pattern is repeated when there are multiple object files; they are mentioned after the link command, one per line.
What's up with this? Why the difference in output format between the two projects? And how exactly does MSBuild obtain the list of object files and communicate it to the linker?
I've compiled boost using:
b2.exe link=shared runtime-link=shared address-model=32 variant=release --layout=system --stagedir=./stage/win32
I'm loading boost components to CMake myself, specifically:
find_path(Boost_INCLUDE_DIR NAMES boost/config.hpp PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../external/boost_1_69_0)
message("${Boost_INCLUDE_DIR}")
add_library(Boost INTERFACE IMPORTED GLOBAL)
set_target_properties(Boost PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR})
find_library(Boost_filesystem_LIBRARY NAMES boost_filesystem PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../external/boost_1_69_0/stage/win32/lib)
message("${Boost_filesystem_LIBRARY}")
add_library(Boost_filesystem UNKNOWN IMPORTED GLOBAL)
set_target_properties(Boost_filesystem PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR})
set_target_properties(Boost_filesystem PROPERTIES IMPORTED_LOCATION ${Boost_filesystem_LIBRARY})
target_link_libraries(Boost INTERFACE Boost_filesystem)
When invoking CMake:
C:/bla/SW/cmake-template/external/boost_1_69_0
C:/bla/SW/cmake-
template/external/boost_1_69_0/stage/win32/lib/boost_filesystem.lib
-- Configuring done
-- Generating done
-- Build files have been written to: C:/bla/SW/cmake-template/build-windows
And last,
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\
bin\HostX86\x86\link.exe /ERRORREPORT:QUEUE /OUT:"C:\bla\SW\cmake-template\build-windows
\mylib\Debug\mylib.dll" /INCREMENTAL /NOLOGO ..\myotherlib\Debug\myotherlib.lib "C:\bla\
SW\cmake-template\external\boost_1_69_0\stage\win32\lib\boost_filesystem.lib" kernel32.lib
user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib
advapi32.lib /DEF:"C:/bla/SW/cmake-template/build-windows/mylib/mylib.dir/Debug/exports.
def" /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PD
B:"C:/bla/SW/cmake-template/build-windows/mylib/Debug/mylib.pdb" /SUBSYSTEM:CONSOLE /TLB
ID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/bla/SW/cmake-template/build-windows/mylib/Debug/
mylib.lib" /MACHINE:X86 /SAFESEH /machine:X86 /DLL mylib.dir\Debug\mylib.obj
LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-x32-1_69.lib' [
C:\bla\SW\cmake-template\build-windows\mylib\mylib.vcxproj]
I don't get it, how come it's trying to link to libboost_filesystem-vc141-mt-gd-x32-1_69.lib and not to boost_filesystem.lib?
That link comes from the auto-ink feature of some of the Boost libraries. You can either adjust the auto-link to use the appropriate naming see macros for controlling this in Boost Config library. Or you can turn off the auto-linking with the BOOST_ALL_NO_LIB macro mentioned also in the Boost Config docs.
My build computer is different than my target (although both are Windows 10).
I am using VS2017 with the latest updates.
The target machine has MFC: 14.12.25810
How do I set my project settings so that I can target that version of MFC. I keep getting an error of: missing MSVCP140D.dll
And when I try to install the VS2015 C++ redistributable, I get an error about conflicting versions. So I would rather stop targeting VS2015, and change to VS2017, or better include the redistributable in the folder I am installing.
Here are my VS2017 Project settings: (I am also using the latest Windows SDK).
UPDATE
I set Static Linked MFC, which added the switch /MTd to the command line:
/permissive- /Yu"stdafx.h" /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"x64\Debug\vc141.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MTd /FC /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\LinkWareMessageBus.pch" /diagnostics:classic
However, now I get a bunch of errors on compile:
Severity Code Description Project File Line Suppression State
Warning LNK4098 defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library LinkWareMessageBus D:\Source\LinkWareMessageBus\LINK 1
Severity Code Description Project File Line Suppression State
Error LNK1120 6 unresolved externals LinkWareMessageBus D:\Source\LinkWareMessageBus\x64\Debug\LinkWareMessageBus.exe 1
Error LNK2019 unresolved external symbol __imp_calloc referenced in function nni_alloc LinkWareMessageBus D:\Source\LinkWareMessageBus\nng.lib(win_thread.c.obj) 1
Error LNK2019 unresolved external symbol __imp_rand_s referenced in function nni_plat_seed_prng LinkWareMessageBus D:\Source\LinkWareMessageBus\nng.lib(win_rand.c.obj) 1
Error LNK2019 unresolved external symbol __imp_strerror referenced in function nni_plat_strerror LinkWareMessageBus D:\Source\LinkWareMessageBus\nng.lib(win_debug.c.obj) 1
Error LNK2001 unresolved external symbol __imp_strncpy LinkWareMessageBus D:\Source\LinkWareMessageBus\nng.lib(http_server.c.obj) 1
Error LNK2019 unresolved external symbol __imp_strncpy referenced in function http_set_header LinkWareMessageBus D:\Source\LinkWareMessageBus\nng.lib(http_msg.c.obj) 1
Error LNK2019 unresolved external symbol __imp__beginthreadex referenced in function nni_plat_thr_init LinkWareMessageBus D:\Source\LinkWareMessageBus\nng.lib(win_thread.c.obj) 1
Error LNK2019 unresolved external symbol __imp__stricmp referenced in function nni_strcasecmp LinkWareMessageBus D:\Source\LinkWareMessageBus\nng.lib(strs.c.obj)
I also tried setting "Ignore All Default Libraries = No" but I still get the same error.
Here is the LINK command parameters:
/OUT:"D:\Source\LinkWareMessageBus\x64\Debug\LinkWareMessageBus.exe" /MANIFEST /NXCOMPAT /PDB:"D:\Source\LinkWareMessageBus\x64\Debug\LinkWareMessageBus.pdb" /DYNAMICBASE "flatbuffers.lib" "nng.lib" "mswsock.lib" "advapi32.lib" "ws2_32.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /IMPLIB:"nng.lib" /DEBUG /MACHINE:X64 /INCREMENTAL /PGD:"D:\Source\LinkWareMessageBus\x64\Debug\LinkWareMessageBus.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Debug\LinkWareMessageBus.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"D:\Source\LinkWareMessageBus\nng\lib" /LIBPATH:"D:\Source\LinkWareMessageBus\flatbuffers\lib" /TLBID:1
What I am doing now is just doing release builds with symbols.
https://msdn.microsoft.com/en-us/library/fsk896zz.aspx?f=255&MSPPError=-2147217396
This is especially useful now, since I am writing plugins for other software that does not like to load debug versions of the DLLs I create. Sometimes you can't see the local stack varibles for a function, but you can always see member and instance variables, as well parameters, so this works best for me, and then one does not have to worry about SDK binding issues like above.
There seems to be an error when generating VS2010 projects from premake, even with the "Hello World" example (Also tried with clink (here) and premake itself)
hello.c
#include <stdio.h>
int main(void) {
puts("Hello, word!");
return 0;
}
premake4.lua
-- premake4.lua
solution "HelloWorld"
configurations "Any"
project "HelloWorld"
kind "ConsoleApp"
language "C"
files "*.c"
defines { "DEBUG" }
flags { "Symbols" }
This simple example fails to link with the message "LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt"
The logfile says:
Build started 09-02-2015 16:06:34.
1>Project "E:\D\Source\premake-dev\pm-test\HelloWorld.vcxproj" on node 2 (build target(s)).
1>InitializeBuildStatus:
Creating "obj\Any\HelloWorld.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D DEBUG /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"obj\Any\\" /Fd".\HelloWorld.pdb" /Gd /TC /analyze- /errorReport:prompt hello.c
hello.c
ManifestResourceCompile:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\rc.exe /nologo /fo"obj\Any\HelloWorld.exe.embed.manifest.res" obj\Any\HelloWorld_manifest.rc
Link:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:".\HelloWorld.exe" /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 /MANIFEST /ManifestFile:"obj\Any\HelloWorld.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"E:\D\Source\premake-dev\pm-test\HelloWorld.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /ENTRY:"mainCRTStartup" /DYNAMICBASE /NXCOMPAT /IMPLIB:".\HelloWorld.lib" /MACHINE:X86 obj\Any\HelloWorld.exe.embed.manifest.res
obj\Any\hello.obj
1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
1>Done Building Project "E:\D\Source\premake-dev\pm-test\HelloWorld.vcxproj" (build target(s)) -- FAILED.
Build FAILED.
Time Elapsed 00:00:00.33
SOLVED!!
It was an error in my pristine VS2010 install!! See
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d10adba0-e082-494a-bb16-2bfc039faa80/vs2012-rc-installation-breaks-vs2010-c-projects?forum=vssetup
Although i never installed anything but VS2010 ..
SOLUTION: From this page:
http://blogs.msdn.com/b/heaths/archive/2011/04/01/visual-c-2010-sp1-compiler-update-for-the-windows-sdk-7-1.aspx
Copy c:\windows\Microsoft.Net\Framework\v4.0.30319\ cvtres.exe (42Kb)
into Programs(x86)\Microsoft Visual Studio 10.0\VC\Bin\
I have a C-File that I wanna compile in Matlab with MS Visual Studio 10.
For that I use the following command:
mex -v test.c
The output that I get after compilation is the following:
test.c
Contents of C:\Temp\mex_kpuu4t\mex_tmp.rsp:
C:\Temp\mex_kpuu4t\test.obj
--> link /out:"test.mexw64" /dll /export:mexFunction /MAP /LIBPATH:"C:\Program Files\MATLAB\R2011a\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /implib:"C:\Temp\mex_kpuu4t\templib.x" /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib #C:\Temp\mex_kpuu4t\mex_tmp.rsp
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Temp\mex_kpuu4t\test.obj
LINK : fatal error LNK1104: cannot open file 'test.mexw64'
C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Link of 'test.mexw64' failed.
Anyone an idea what could go wrong here? The interesting thing is, that the test.obj file seems not to be written to the temp folder, could that be the issue here?
Many thanks!
Maybe you called "test" from a previously compiled mex? If yes, it might still be loaded to Matlab's memory, and cannot be overwritten. Try:
clear mex
and then compile again.