EDIT2: problem solved with adding libucrt.lib to link options
I'm trying to compile resource only DLL-file with VisualC++ 2017 compiler. Here is my command line:
cl test.cpp /link /dll /noentry "E:\CXGE\build\Debug\CXGE.lib"
Test.cpp contains some basic functions and math operations. But for some reason I can't use any of c++ math functions like std::sin, std::cos and std::abs in my DLL file because of this linking error:
test.obj : error LNK2019: unresolved external symbol fabs referenced in function "double __cdecl abs(double)" (?abs##YANN#Z)
Can someone say which libraries do I need to link to fix these errors? I'm on Windows 10, using Visual C++ 2017 compiler
EDIT: I am using X64 Native tools command prompt for VS 2017
C Runtime libraries are missing. Either include them or try to compile using VS command prompt.
These functions are in the math library. Under Linux, you'd typically link this just by adding '-lm' to the compilation line. I'm not sure of the equivalent for VC++, but hopefully it's something similar.
Related
I am trying to use a library compiled with mingw in visual studio. However, I get the following linker errors:
error LNK2001: unresolved external symbol __imp___iob
error LNK2019: unresolved external symbol __imp___pctype referenced in function
error LNK2019: unresolved external symbol __imp____mb_cur_max referenced in function
error LNK2001: unresolved external symbol _fprintf
I was able to fix the _fprintf error by linking against legacy_stdio_definitions.lib as per this post : unresolved external symbol __imp__fprintf and __imp____iob_func, SDL2.
However, I have no idea how to fix the other three unresolved externals. How can I fix this? The libraries work perfectly under Visual Studio 2013.
Edit:
Okay here is an update. I moved libmsvcrt.a from the mingw lib folder into Visual Studio, and I added that to the linker settings. Now it seems to work correctly.
The libraries were compiled against an old version of the CRT. The unresolved symbols you get are internal symbols of the CRT that are present in the compiled library. You have to recompile the library against the VS2015 CRT (the Universal CRT). But I'm not sure if MinGW supports this.
If you can't do that, you have to continue to use the VS2013 compiler. (You can use the VS2015 IDE, by setting the toolset to vs2013 in the project options. But you'll still be limited to the C++ features the 2013 compiler supports.)
I encountered the same problem (library compiled with static CRT instead of CRT in DLL) and I managed to make it work by changing the two following parameters in Project Properties:
Linker > Input > Ignore specific default libraries: libc.lib
C/C++ > Code Generation > Runtime Library: Multi-threaded Debug (/MTd)
If that's not enough, there's more at following page: https://social.msdn.microsoft.com/Forums/en-US/841e5723-bce4-4340-b7b3-027dcdf90f00/
I switched my Visual C++ 2012 project from Multi-threaded Debug (/MTd) to Multi-threaded Debug DLL (/MDd). The project is a mixture of C++ .vcxproj and Intel Fortran (.vfproj) projects. After all is rebuild I get the errors below.
In CRT source code I see the offending symbols are defined in crt0dat.c if CRTDLL symbol is not defined. How do I make sure I get crt0dat with CRTDLL when compiling main application?
Any other suggestions how do I troubleshoot this?
50>cmain.obj : error LNK2019: unresolved external symbol _initp_misc_cfltcvt_tab referenced in function wWinMain
50>cmain.obj : error LNK2001: unresolved external symbol _FPinit
50>C:\spm\git\clones\SPM80_dll\MSBuild\x64\dll_debug\SPM_dll_debug_x64.exe : fatal error LNK1120: 2 unresolved externals
I believe /MDd builds require msvcrtd.lib. This should be something that automatically gets linked into your project; it might be that it's ignored through a project setting. Open the Project Settings for the C++ project and look under Linker->Input. There are settings there for Ignore All Default Libraries and Ignore Specific Default Libraries. See if there's anything there that might cause the linker to ignore msvcrtd.lib.
BTW, your code will also need the appropriate DLL to run, which for VS 2012 would be msvcr110d.dll. This should already installed on your machine when you installed VS 2012, but it will have to be distributed with the executable if you move it to another computer.
I just switched to Octave from Matlab and would like to continue to compile mex-files as a DLL through visual studio.
I have a project which creates a dll and exports the mexFunction as previously. I also include the mex.h file found in Octave but I have trouble linking.
Currently I get a linking error stating:
error LNK2019: unresolved external symbol __imp_mexPrintf referenced in function mexFunction
I understand why but I don't know what to include to resolve this issue.
Can anybody help?
Thanks
Henrik
The files are found in:
C:\Octave\Octave-3.8.2\lib\octave\3.8.2
and I used liboctave.dll.a and liboctinterp.dll.a
i have compiled c++ files and make it as a lib using cygwin in windows. when i try to use that lib in visual studio 2005 c++. it produces the following errors.
"Error 1 error LNK2001: unresolved external symbol ___gxx_personality_v0 mylib.lib
Error 2 error LNK2019: unresolved external symbol __Unwind_Resume referenced in function _fjfx_create_fmd_from_raw mylib.lib
Error 3 error LNK2019: unresolved external symbol ___chkstk referenced in function __fjjj mylib.lib"
how to resolve it.
Yes, you need to build your library using the visual studio tools. The "gxx_personality_v0" is a symbol created by the g++ compiler, and can only be resolved by linking with the relevant libstdg++ library. Same for the other components.
Unfortunately, some parts of the runtime support for one compiler doesn't match when using a different compiler.
You could possibly get away with it if you link your Visual Studio code with the relevant GNU libraries, but I'm far from convinced.
[And I fully expect you to explain that the reason you compiled using cygwin is that the code contains a bunch of stuff that can't be compiled with Visual Studio because it uses gnu compiler extension features...]
I'm obtaining this link error and I cannot find the solution. Can you maybe put me in the right direction where to search for it?
I get: error LNK2019: unresolved external symbol _imp_pthread_mutex_lock referenced in function "private: bool __thiscall... here comes the whole name of my function with parameters.
pthread_mutex_lock and pthread_mutex_unlock are used in this function (not as arguments).
Including "pthread.h" doesn't change anything.
I used pthread-win32 available from sourceware.org/pthreads-win32.
I've been facing this issue for couple hours now and was finally able to fix it by adding the 'lib', 'include' and 'bin' folder content provided with the download, in the appropriate folders in Visual Studio dependency installation folder.
Mine is in
"C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\VC\Tools\MSVC\14.10.25017"
Then i added the library dependency 'pthreadVC2.lib;' in
Project -> Properties -> Linker -> Input -> Additional Dependancies
And voila! pthreads started to work.
The pthread library is for POSIX systems (Linux, BSD, Mac OS). You indicated that you're on Visual Studio in Windows - if you are looking to do multithreading on Windows, see this page.
Better yet, if you can use more recent tools, C++11 offers built-in threading functionality.
You need to add
-lpthread
or
-lthread
to your compiler command line (depending on OS and compiler)
UPDATE: #nos correctly points out that this seems to be a MS linker error. You shouldn't be using pthreads in Visual Studio. Windows Threading API is very different.