LibCurl in Visual Studio 2013 Static Linker Errors Even After Including Necessary Dependencies - c++

So first I'll say I've looked in a ton of places to no success.
This PDF is where I started:
http://curl.haxx.se/libcurl/c/visual_studio.pdf
It seems outdated and does not include instructions for statically linking libraries. Or at least, I've tried following all of the instructions without any success.
I've tried following answers in
Installing LibCurl on Visual Studio 2010
error LNK2019: unresolved external symbol libcurl Visual studio
Building libcurl library in Visual Studio 2008
and other areas, but have not made any progress.
I will also say that I am NOT a Windows user by any stretch of the imagination. With that said I will lay out what I have done so far.
I am porting over an application I made in a Unix environment, specifically OSX. I've made a lot of progress with the exception of using libcurl. I need to statically link LibCurl so that the executable built by Visual Studio can be moved to other Windows devices as necessary without needing dlls for libcurl or MySQL (which I am also linking statically).
Anyway, with the gracious help of this repository:
https://github.com/blackrosezy/build-libcurl-windows
I was able to build libcurl onto my Windows device. This was a difficult process before I found this repository. Now I have a lib and an include folder. Inside the lib folder there are release and debug folders for dll and static builds each. Inside the static-release folder I have ONLY libcurl_a.lib. Inside the dll-release folder I have libcurl.dll, libcurl.lib, and libcurl.pdb.
I have gotten the program to SUCCESSFULLY build when dynamically linking from the dll-release folder. However, when I try to link statically from the static-release folder, I get 11 or so linker errors.
I have also included "libcurl_a.lib", "wldap32.lib", "ws2_32.lib", "winmm.lib", "libeay32.lib", and "ssleay32.lib" as dependencies.
In addition to all of this, I used NuGet to get libssh2.1.4.3.1, openssl.1.0.1.21, zlib.1.2.8.1 along with redist versions of all of these. I have included the following paths in my library directories as well:
path_to_libssh\build\native\lib\v110\Win32\Release\static\cdecl\<br>
path_to_openssl\build\native\lib\v110\Win32\Release\static\cdecl\<br>
path_to_zlib\build\native\lib\v110\Win32\Release\static\cdecl\<br>
I have also put the /include/ paths from these folders in my list of include directories.
In my preprocesser definitions I have "CURL_STATICLIB".
However, despite all of these steps that I have taken from multiple sources including some great answers on this site, and the PDFs and some answers on the LibCurl site, I am still having these linker errors.
As an example, one of the errors that I feel is slightly indicative (sorry I cannot copy and paste all of these errors from VS2013 that I can tell) says:
"error LNK2019: unresolved external symbol curl_easy_setopt referenced
in function 'public:__cdecl Curler::Curler(char*)'(??0Curler##QEAA#PEAD#Z)"
All of these errors are laid out similarly, pointing to some sort of __cdecl Curler function, with the error code LNK2019.
Anyway, my question is basically: what am I doing wrong? I am sorry if this is a vague question, or if you feel as though this is a repeat. But I can assure you that I have looked at a large list of Stack Overflow questions and other areas of the internet with no success, and I've begun to feel very lost. Things that seem to work for so many others I just cannot get to work. I think a large portion of the problem is my newness to Windows. If there is any other information that I can provide in order to help you help me, then I will gladly provide it. I really appreciate any help you can give me. Thanks.

First of all, thank you to user Pawan who edited my post; it was my first post and he helped make it up to standards aesthetically with the community so I know what to do in the future.
Anyway, I think I solved my problem. It's probably a bit of an edge case, but it worked for me anyway.
After a while, I decided to build libcurl for Win64 using Visual Studio. To do this, I grabbed the code from this helpful repository:
https://github.com/bagder/curl
I cloned it, and navigated to that directory. I then ran the following commands (this is in Powershell so I used unix-esque commands, but I did not use MinGW for this):
mkdir build
cd build
cmake .. -G "Visual Studio 12 2013 Win64"
This built a Visual Studio Solution that I could open in Visual Studio 2013. In Visual Studio, I went to
Project Properties -> C/C++ -> Code Generation
And switched the Runtime Library option to "Multi-threaded (/MT)"
Then I built the project, which outputted the following files in the following path:
path_to_pulled_code\build\lib\Release\libcurl.dll
path_to_pulled_code\build\lib\Release\libcurl_imp.exp
path_to_pulled_code\build\lib\Release\libcurl_imp.lib
So, now I had the lib file I needed. Now, in:
Project Properties -> Linker -> Input
I put "libcurl_imp.lib" and "ws2_32.lib" under Additional Dependencies.
As I've said before, I made sure that I had "CURL_STATICLIB" in Preprocessor Definitions. I also switched Runtime Library to "Multi-threaded (/MT)" for this project.
After all that, well, it compiled! For some reason I needed to copy libcurl.dll that the aforementioned Visual Studio build of bagder's repo made into my executable path in order for the solution to actually work. But it seems to be working now at least!
Thanks guys. Hopefully this answer will help anyone else who stumbles onto this problem like I did.

Related

C++ detours linking issue

I have problems building my code that is using static lib detours. I am trying to do an old basic CTF. For that I want to get into detours.
Whenever I try to build my .dll file I get an issue
LNK2019 unresolved external symbol _DetourTransactionBegin#0 referenced in function _DllMain#12
Now, I have built the detours library using 3 different version of the visual studio dev console.
I have tried firing 'vcvars32.bat' and then using nmake to build the library which was able to build it, but I get the above error during linking my .dll. I have also tried building it with 'vcvarsamd64_x86.bat' and then using nmake to build it which also was able to build the library, but I still get the same error as above during linking.
I have tried the usual stuff: the include folder for detours.h is added to C++/General/Additional Include Directories.
Under Linker/Additional Library Directories I added them as follows: "C:\temp\det_retry\lib.X64";"C:\temp\det_retry\lib.X86";%(AdditionalLibraryDirectories).
And also under Linker/Input/Additional Dependencies I have the following: detours.lib;%(AdditionalDependencies)
What am I missing here? This is a blocker for me for a couple of days and I am reiterating the same steps trying to figure out what's missing but I cannot see. I'd really appreciate the input.
I am sure I am using the newest version because I have downloaded (cloned) detours from the ms github page.
It appears your "Additional Library Directories" are setup incorrectly or contain invalid entries rather. They look like actual library file entries (i.e. pointing to some specific files) versus being only directories (e.g. "my/lib/path/for/my_project/"). Visual Studio's naming conventions are somewhat cryptic but they should be directory entries only. There should be an entry to whatever directory contains the detours.lib file (e.g. "MyProject/Libs/MSDetour" ... where MSDetour is a folder with the "detours.lib" in it) and then Visual Studio should find the library and link everything correctly.
As a side note, if you are using the Visual Studio developer console for building your project/solution you might want to look into CMake ... it is, in my opinion, significantly easier to work with (less "settings" digging) and maintain in the long-run.

Linking libpqxx from Visual Studio 2015 on Windows 10

I've recently decided to try out PostgreSQL as the database platform for some C++ development I'm working on. I decided to use libpqxx as the connection library for my project, and quickly found out this would be an uphill battle to do from VS 2015 on a Windows 10 machine.
After much teeth-gnashing and nail-biting, I have gotten libpqxx to compile on Windows 10.
This leaves me with the following directory structure
Per libpqxx's documentation, I also placed a copy of libpq.dll in my project's executable directory. Please note: I have done this for both debug and release builds, tried to build both, and ended up with the same result.
All the tutorials I've seen seem to indicate that the library can be used after linking it and simply #including pqxx/pqxx, so I set up a small project to do just that. I receive the error:
fatal error C1083: Cannot open include file: 'pqxx/pqxx': No such file or directory
When attempting to build the project. I have also tried this will both debug and release builds, to no avail.
Here is a screenshot of my linker settings.
Does anyone have any suggestions for how I might be able to link and use this library from Visual Studio 2015?
As Sami Kuhmonen pointed out, this was not actually a linker error, but a compiler error. I needed to include an actual header, which Visual Studio needed to be able to find. After adding the correct folder (C:\libpqxx\include in my case) to Visual Studio's "additional include directories" setting under C\C++ -> General per drescherjm's suggestion, the program compiles just fine.
For future reference:
I did also run into unresolved external linker errors after solving the initial issue. This is because you need to make sure to also link to ws2_32.lib and libpq.lib. You also need to copy some other DLL files that libpq also relies on into your libpqxx lib folder. On my system, I believe these were ssleay32.dll, libeay32.dll, and libintl-8.dll. These files reside under the root of the PostgreSQL install. The DLL step is mentioned under libpqxx's INSTALL.txt file, however I believe it stated that the DLLs resided one folder under where I actually found them.
I have also faced same issue. Then I realized that I was building ,my application as a 32bit. I changed the target to x64 and it compiled successfully

Building & Linking FreeImage with Visual Studio Express 2013

I'm having a lot of trouble linking my project with FreeImage library with VSE 2013
I've followed this answer for VS2010 to no avail: Linking FreeImage as a static library in VS2010?
I am getting LNK2019 errors when calling FreeImage functions.
I've linked the library just as I would any library. Below are the following steps I made:
Download FreeImage Source.
Open the 2008 Solution (converted to 2013) and changed Code Generation to /MDd for all projects
Attempted to build project but for some reason min/max functions were not defined So I included algorithm.h to those files and that stopped those errors.
Attempted to build project and I get an error: "Could not open "afxres.h". So I swapped afxres.h with windows.h as suggested in another topic.
Built the project -> success
Copied Fresh FreeImaged.lib to to my project
Added directory to "Additional Library Directories"
Added FreeImaged.lib to Additional Dependencies under linker
Copied FreeImaged.dll to my debug folder where the .exe is being built
Added FreeImage.h to the project
Added #define FREEIMAGE_LIB before including the header
Attempted to build my project -> LNK2019s everywhere.
If anyone has been able to build FreeImage on VS2013 and could share how they did it I would greatly appreciate it, or if anyone has any suggestions.
The reason for your troubles is that with Visual Studio 2013 some breaking changes (as outlined by Microsoft) were introduced in related to C++11 conformity.
One includes that in order to use std::min()/std::max(), you now have to include the header . This also concerns FreeImage. Unfortunately, up until version 3.6.1 (the most recent as of today) this hasn't been fixed yet.
This blog post explains what you need to do to get it to compile. The most relevant part is:
Specifically, you will need to add
include <algorithm>
to the following files:
Source/OpenEXR/IlmImf/ImfOutputFile.cpp
Source/OpenEXR/IlmImf/ImfScanLineInputFile.cpp
Source/OpenEXR/IlmImf/ImfTiledMisc.cpp
Source/OpenEXR/IlmImf/ImfTiledOutputFile.cpp
Source/OpenEXR/Imath/ImathMatrixAlgo.cpp
I was able to get this to work by going into the Configuration Manager unchecking FreeImage and checking FreeImageLib under build. Also disabling whole program optimization seems to make the binary size more normal and, gets rid of warnings when linking.
I know this question is over a year old. Just providing an answer to anyone google searching this problem like me.
version: FreeImage3170Win32Win64.zip
os.env.: win7 64bit visualstudio ULTIMATE 2013
operation:
1_ just unpacking the zip somewhere
e.g. (D:/library/FreeImage3170Win32Win64/FreeImage)
2_ in C/C++->General->Additional Including Directerories
add (D:/library/FreeImage3170Win32Win64/FreeImage/Dist/x32)
3_ in Linker->General->Additional Library Directerories
add (D:/library/FreeImage3170Win32Win64/FreeImage/Dist/x32)
4_ in Linker->Input->Additional Dependency
add (FreeImage.lib)
PS0: i just add a new entry to Include Directories and Library
Directories and FreeImage.lib to Linker->input in Visual Studio without rebuild the FreeImage library
:)
PS1: error LNK2019 occured when i added the FreeImage/Dist/x64 option
;( ( got no idea about this)
maybe this helps :)

CMake And Visual Studio build errors

I've been trying to compile tulip using cmake to generate visual studio 2012 project files. It's giving me lots of trouble. I don't know how to get this to build. I've been trying to get visual studio to build this for 4 days now, and I'm extremely frustrated. Essentially, I follow the steps here, and then set the variables CMAKE_LIBRARY_PATH AND CMAKE_INCLUDE_PATH according to these instructions.
To get to where I'm at, all you have to do is download tulip, and:
Unzip it, create a separate build directory outside of this source directory
Open CMake-gui to the source and build directories
Hit configure. Check use qt5, tell it where qmake is (make sure it's qt5)
You need some dependencies as described in The Independent CMake tutorial. Grab all those dependencies
As you continue to hit configure, specify each of the directories that it asks for as it errors out. It should ask for freetype, glew, zlib and sphinx. It shouldn't ask for where libxml or libpng, or libjpeg are. I don't know why it doesn't ask for those.
Generate, and then browse to the ALL_BUILD that you've generated. Open it with visual studio
try to build it with visual studio.
In those instructions and in the process of getting CMake to generate the visual studio build files, it specifically asks for freetype's location. But in my build, it doesn't have a clue how to link the freetype library.
Here are the errors that I get
Here is my CMakeCached.txt
I know that many people aren't going to want to exactly try and go about replicating the build environment, so I've uploaded my build directory to dropbox. You can pull the entire thing down, and then open it in cmake gui and open the visual studio files in there too.
https://www.dropbox.com/sh/qsvukh9t5gb6bvt/tOfOBxWgd0
The linker errors you point to (mostly "unresolved external" errors) indicate that there are missing libraries on the link command line.
That is most likely happening because target_link_libraries calls in the tulip project are either being skipped or being called with library names that do not match the library names on disk.
Open up the solution in Visual Studio and right click the project and choose "Properties" -- look at the "Linker > Input" panel at the "Additional Dependencies" field. That should list all the libraries it wants to link to. Is there a freetype library listed there? Does that library exist in the referenced location on your disk?
There could be a mistake in the tulip project, or there could just be something wrong with your build/install of freetype...
UPDATE AFTER SOME CHAT:
Or it may be that you have some libraries built for x86 and some for x64... or maybe some for Debug and some for Release... or maybe even some with the MinGW compiler and some with the Visual Studio compiler. If that's the case, start over, from a clean slate, and build everything with a consistent compiler, configuration type and architecture. Then report back again with an update and see if the problems still remain.
I do with Dave,
You should try to fix your error 1 by 1.
The first error seems to be a link error:
Error 1 error LNK2019: unresolved external symbol gzread referenced in function "public: virtual int __cdecl gzstreambuf::underflow(void)" (?underflow#gzstreambuf##UEAAHXZ) C:\Users\kenne_000\tulip-build\tulip-build-debug\thirdparty\gzstream\gzstream.obj gzstream
gzstream is a third party lib included with tulip source in:
thirdparty\gzstream
from
thirdparty\gzstream\CMakeLists.txt
you can see that the missing symbols should be coming from ZLIB.
However your CMakeCache.txt indicate that
ZLIB_LIBRARY:FILEPATH=C:/Users/kenne_000/dependencies/zlib128-dll/lib/zdll.lib
is found.
So the question may be, was this dependency compiled with the same compiler?
Don't you have compiler-specific name mangling issue ?

Using a DLL with unmanaged code in Visual Studio 2010?

I'm fairly new to C++ and an trying to figure out to use the TagLib library for a project I am working on. I'm working with unmanaged C++ in Visual Studio 2010 on Windows 7 64bit. I've never used an external library before so I'm very confused on how to go about this.
From this blog entry I got the libtaglib.a and taglib.dll files. I ran across this SO question on how to use TagLib, but it deals with QT Creator, not Visual Studio and I'm not knowledgeable enough about the subject to understand what is being said to translate it into what needs done for Visual Studio.
So, some questions:
Is it even possible to do this with unmanaged code?
What exactly is the function of a .a file?
Most importantly, how do I go about using the taglib.dll in my program??
I've been all over Google looking for a way to do this, but my major problem is that everything I run across is over my head. Please let me know if more info is required. Any help is very much appreciated! Thanks!
I seem to have gotten it working successfully. Here's a rough outline of what I did:
1.) I used CMake to generate the Visual Studio solution.
2.) I attempted to build the tag project in the VS solution, but it failed.
3.) I made the corrections to a few source files as outlined here: http://old.nabble.com/taglib-fails-to-compile-with-MS-VC%2B%2B-2010-td29185593.html
4.) I built the tag project again in release mode. This time it was successful.
5.) I copied the resulting dll, def, and lib files to the same directory as the source files for my project.
6.) I copied the header files from the taglib source to a subdirectory in my project (not sure if this entirely good practice)
7.) In my project settings, I set the subdirectory with the header files as an additional include directory.
8.) I added the dll, exp, and lib files to my project by just going to Add>Existing Item.
9.) I added some code from the taglib examples and built it. Everything worked so I think I got it.
One caveat I ran into, since the DLL was built in release mode, my project had to be run in release mode or it would crash. I'm guessing that if I replaced the DLL with one built in debug mode I could run my program in debug mode, but I have not tried this.
You cannot use libraries specific to GCC (you can tell because they have .a extensions) with Visual Studio. You will have to build the library from source in order to use it with MSVC. Once you have done that it's a simple matter of adding the .lib generated from the build process to your project and things should work out of the box. (Note that it's a .lib you need whether you're compiling for dynamic linking or not -- doesn't matter in msvc land)
EDIT -- after looking at TagLib itself --
In order to compile TagLib you'll need to get the CMake build system, and TagLib itself, and have CMake build you a visual studio solution. Using that solution you'll be able to build the .libs and .dlls you need. Note that because TagLib is a KDE library, you'll probably need to also build some QT bits in order for everything work work successfully. However, I don't have specific experience with the library so I'm not going to be all that helpful here.
Yo do not have to recompile the source (to create the .lib file) if you have the .dll file. With dumpbin /exports and lib (both came with Visual Studio) yo can create a lib that you can link with your application. In this link you can see a nice explanation: http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/
But as Billy Said, probably you would need other parts of QT to use this library.