I built CURL static lib from source using this command in the x64 Native Tools Command Prompt Visual Studio
nmake /f Makefile.vc mode=static MACHINE=AMD64
I added the lib folder to the linker library folder, added libcurl_a.lib to the linker input, and added the include folder to additional include directories. I also used the pre-processor define CURL_STATICLIB.
The library links successfully and the header is found. But I get 60 unresolved external symbols when I try to compile. https://hastebin.com/vukekakoti.tex
Dynamic linking is working with no problems.
How can I solve this?
I was missing definitions contained in these libraries:
libcurl_a.lib;ws2_32.lib;wldap32.lib;advapi32.lib;kernel32.lib;comdlg32.lib;crypt32.lib;normaliz.lib
Add those to your additional dependencies.
if compiling CURL with static linking, you will need to specify on the preprocessor field:
CURL_STATICLIB
and also as mentioned above, you`ll need to link with dependent libraries.
Related
In my current project I'm using the library libcurl, previously installed by powershell. I'm including it using #include "curl/curl.h" and compiling works but I have a linking error that says:
:LNK1104:cannot open file curl/libcurl_a_debug.lib
I dont have this file. In my current directory i found only libcurl.lib. I already added the path to the directory in Additional library directories and Additional include directories. I'd like to know is any other way to solve this error.
In release mode i have an error that linker cannot open file libcurl_a.lib. On the other hand in debug folder i have a libcurl-d.lib file.
According to Microsoft Docs, there are several common causes for this issue:
The path to your library file may be incorrect, or not wrapped in
double-quotes. Or, you may not have specified it to the linker.
You may have installed a 32-bit version of the library but you're
building for 64 bits, or the other way around.
The library may have dependencies on other libraries that aren't
installed.
By the way, could you add libcurl.lib in Properties->Linker->Additional Dependencies? If not, you could add it.
You could try to use compiled statements instead of settings.
#ifdef _DEBUG
#pragma comment(lib,"..\\debug\\lib name")
#else
#pragma comment(lib,"..\\release\\lib name")
#endif
Also, I read the official documentation of curl. There is a description of Windows link errors:
5.7 Link errors when building libcurl on Windows!
You need to make sure that your project, and all the libraries (both static and dynamic) that it links against, are compiled/linked against the same run time library.
This is determined by the /MD, /ML, /MT (and their corresponding /M?d) options to the command line compiler. /MD (linking against MSVCRT dll) seems to be the most commonly used option.
When building an application that uses the static libcurl library, you must add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for dynamic import symbols. If you're using Visual Studio, you need to instead add CURL_STATICLIB in the "Preprocessor Definitions" section.
If you get linker error like "unknown symbol __imp__curl_easy_init ..." you have linked against the wrong (static) library. If you want to use the libcurl.dll and import lib, you don't need any extra CFLAGS, but use one of the import libraries below. These are the libraries produced by the various lib/Makefile.* files:
Target: static lib. import lib for libcurl*.dll.
-----------------------------------------------------------
MingW: libcurl.a libcurldll.a
MSVC (release): libcurl.lib libcurl_imp.lib
MSVC (debug): libcurld.lib libcurld_imp.lib
Borland: libcurl.lib libcurl_imp.lib
I suggest that you could try the method.
I'm using Visual Studio 2017 and I'm trying to link to openssl 1.0.2 built by me as 64-bit Release static library as shown here. Actually it's my lib (also static) that is using openssl functions directly and executable is linking to this lib. I tried two approaches:
Put openssl's symbols into mylib.lib (using a tab in VS mylib's project properties called "Librarian")
Link to openssl (libeay32.lib, ssleay32.lib) and to my lib using Linker in executable's project
Both are resulting in linker errors like
error LNK2001: unresolved external symbol EVP_EncryptInit_ex
concerning mylib.lib library.
I looked into libeay32.lib (also into mylib.lib while using the Librarian approach), using dumpbin.exe provided by Visual Studio, and there's _EVP_EncryptInit_ex (note the _ at the beggining) symbol defined. So I'm wondering whether it is possible that openssl defines _EVP_EncryptInit_ex and the executable is trying to link to EVP_EncryptInit_ex? What could be the cause and solution? Also: How can I check for sure what symbols is exectuable trying to link to?
I'm having an issue compiling a static library using Code::Blocks 13.12. I need to use a third party static library from within my own static library. So, I have libOtherLib.a and I'm trying to build libMyLib.a and link in libOtherLib.a. The problem is that the linker is not including libOtherLib.a during the linking phase of the build. Here is some additional information:
I am using the GNU GCC Compiler
In Project build options for the whole project (not specifically Debug or Release)
I have added libOtherLib.a in the Link Libraries list in the Linker Settings
I have added the path to libOtherLib.a in the Search directories -> Linker list
I have added the path to the .h file for libOtherLib.a in the Search directories -> Compiler list
The library compiles completely fine (produces bin/Debug/libMyLib.a with no errors)
Any help would be greatly appreciated. I have an inkling that it is related to this being a Static Library rather than an application (console or otherwise), but I'm not sure how or why. I did change the build target Type to "Console Application" in the Project Properties window and it looked like it was linking in libOtherLib.a, but it had other errors because this code is meant to be a library rather than an application.
Here is the linker command that is executed at the end of the build. libOtherLib.a is not there anywhere, that is the problem, just not sure what the solution is.
ar -r -s bin/Debug/libMyLib.a <all of my .o files>
Possible causes of the problem would also be nice - if this is mostly like the compiler, the linker, the setup or Code::Blocks itself.
When building a static library you are just putting together a bunch of object files into an entity easier to ship and use. There is no linking done when building a static library.
The unresolved references from your library are dealt with when building an application or certain shared objects. You'd just ship your library and require that users also supply the library your library deoends on when building.
If you want to include the library you are depending on in your library you can extract the object files from tgat library and include them into your library. Although technically possible it is questionable if you have the rights to do so. Also, that is normally not the way things are done and I'd recommend against doing so.
You can't link a static library in anoter static library.
However,you can do this:
Suppose MyPrograme.exe need to link static library libMyLib.a,make MyPrograme.exe also link libOtherLib.a.
Since libMyLib.a is static library,there is no need to link libMyLib.a.Just inclue the headers.
When build a static library,it will only be compiled,not be linked.
Despite all this "linking is not the right term for this" philosophy, you can patch Code::Blocks compiler configuration to support this, for example for the GCC/G++ compiler.
http://green-candy.osdn.jp/codeblocks_config.html
The idea is that you replace the "Link object files to static library" script in the "Advanced compiler options" window of GCC with:
rm -f $static_output
$lib_linker -r -s -T $static_output $link_objects
$lib_linker -r -c -T $static_output $link_options
Then you can put the relative path to your "libOtherLib.a" in the "Other linker options" editbox of your projects. This mod is not really officially endorsed but it works in my projects, so you get static libs in static libs just like in MS Visual Studio!
I have seen several other answers in order to add a library to my C+= project in eclipse.I have tried to add the path to the linker in Miscellaneous section using -L"and the path of the folder" and -l"the name without the lib prefix in the begging and the .so at the end"
I try to add libxl library so i use -lxl (for libxl.so) and -L/home/username/libxl3.5.3.0/lib/ (which the location of the lib file).
I have also tried to give it under the Linker menu and adding the name and the path in the Libraries section.
I get error that: /usr/bin/ld does not find -lxl file and it returns error
I am using -static to linker in order to make an executable that has the all the libs included but when i do not use -static the problem with the lib resolves from build but still when i try to run the program i get error that i the program can not open shared file libxl.so cause the file does not exist.How can i fix this?
When you add the library name to a C++ project in eclipse, do not prefix it with -l. Eclipse will do this for you when it invokes the compiler. For example if you want the boost_regex library, just input boost_regex not lboost_regex. Eclipse will do the rest for you. Or in your specific case, just use xl not lxl. You don't need the - either, nor the -L before paths as erenon points out in the comment below. Note that the above applies to the method of adding libraries using the Project->Properties->C/C++ General->Paths and Symbols dialog form for adding libraries using the Libraries and Library Paths tabs.
You are trying to link statically to a shared library. In my experience I have always used *.a files rather than *.so files to employ static linkage. This other answer Static link of shared library function in gcc seems to suggest that you are not actually able to link statically to *.so files.
I'm just getting started with Boost for the first time, details:
I'm using Visual Studio 2008 SP1
I'm doing an x64 Build
I'm using boost::asio only (and any dependencies it has)
My code now compiles, and I pointed my project at the boost libraries (after having built x64 libs) and got past simple issues, now I am facing a linker error:
2>BaseWebServer.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_system_category(void)" (?get_system_category#system#boost##YAAEBVerror_category#12#XZ)
2>BaseWebServer.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_generic_category(void)" (?get_generic_category#system#boost##YAAEBVerror_category#12#XZ)
any ideas?
I added this define: #define BOOST_LIB_DIAGNOSTIC
And now in my output I see this:
1>Linking to lib file: libboost_system-vc90-mt-1_38.lib
1>Linking to lib file: libboost_date_time-vc90-mt-1_38.lib
1>Linking to lib file: libboost_regex-vc90-mt-1_38.lib
which seems to indicate it is infact linking in the system lib.
I solved the problem. I had built 32-bit libraries when I had intended to build 64-bit libraries. I fixed up my build statement, and built 64-bit libraries, and now it works.
Here is my bjam command line:
C:\Program Files (x86)\boost\boost_1_38>bjam --build-dir=c:\boost --build-type=complete --toolset=msvc-9.0 address-model=64 architecture=x86 --with-system
#include <boost/system/config.hpp>
In my case, BOOST_LIB_DIAGNOSTIC did not show system being automatically linked in. I resolved this by simply including boost/system/config.hpp.
You need to link in the boost_system library
I had the same problem. I tried all described above, but nothing helps. The solution was simple: first I worked with an empty project and there I had linker error LNK2019. But when I created new default Win32 console application with stdafx.h, targetver.h and stdafx.cpp files everything worked. May be it will be useful for somebody, I spend two days for this
If you use boost::system in your project, you should use and appoint the x86 or x64 version of boost::system lib.
You can recompile Boost library with the following batch file. Save these to the Boost root folder and run it in CMD Windows (don't double click!):
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86
cd boost_1_60_0
call bootstrap.bat
rem Most libraries can be static libraries
b2 -j8 toolset=msvc-14.0 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64
b2 -j8 toolset=msvc-14.0 address-model=32 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/win32
pause
For more details, you can see this article: https://studiofreya.com/2015/12/19/how-to-build-boost-1-60-with-visual-studio-2015/
I came to the question via searching for the linker error plus CMAKE, so I'm adding this comment here in case anyone else finds this question the same way.
It turns out that the linker error in my case was due to an errant:
add_definitions(-DBOOST_ALL_DYN_LINK)
in the CMakeLists.txt, which is fine for Unix, but not Windows in my case. The solution is not use that define on Windows.
I needed both versions and used stage target, so I used --stagedir=./stageX86 for x86 version and the default ./stage for x64
I also came here from for this linker error plus CMake, but in my case it was the fact that CMake by default will try to build with 32bit by default. This was fixed by specifying -Ax64
cmake -Ax64 {path to CMakeLists.txt}
None of the methods worked for me given before in this thread.
Then I checked the files inside boost system folder and tried below #define
#define BOOST_ERROR_CODE_HEADER_ONLY
The linking error is solved after using this.
In my case, I resolved this by moving the boost include dir from
Project -> Properties-> VC++ Directories -> Include Directories
to
Project -> Properties-> C/C++ -> General -> Additional Include Directories
, and moving the boost lib dir from
Project -> Properties-> VC++ Directories -> Library Directories
to
Project -> Properties-> Linker -> General -> Additional Library Directories
Maybe the error is caused by link order.