CMake And Visual Studio build errors - c++

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 ?

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.

code execution cannot proceed because cpprest_2_10.dll was not found

My aim is to use the Rest API in Visual Studio.
I downloaded the C++ tool vcpkg from https://github.com/Microsoft/vcpkg and followed the instructions on https://github.com/Microsoft/cpprestsdk to install cpprestsdk. That worked fine.
Then, in Visual Studio in the properties of the solution explorer, I included the following paths from the vcpkg folder into "VCC++ Directories->Include directories":
vcpkg-master\vcpkg-master\buildtrees\cpprestsdk\src\v2.10.2-718a4e55e9\Release\include\cpprest
vcpkg-master\vcpkg-master\buildtrees\cpprestsdk\src\v2.10.2-718a4e55e9\Release\include
vcpkg-master\vcpkg-master\buildtrees\cpprestsdk\src\v2.10.2-718a4e55e9\Release\include\pplx
Then I run my code and the following errors occur:
LNK2001 unresolved external symbols (32 errors like this)
I googled it and was told to include the respective ".lib"-files into "Properties->Linker->Input->Additional Dependencies" and to include the paths of the corresponding ".dll"-files into "Properties->Linker->General->Additional Library Directories", what I did.
Now, running the code again, just the following error occurs:
code execution cannot proceed because cpprest_2_10.dll was not found. Reinstalling the program may fix the problem,
although the "cpprest_2_10.dll" is in the path, which I included previously.
I have no idea what the problem is. Thank you in advance for your time.
Try to put the missing dll file right to the directory of your compiled exe.
Or check this answer to set a path so your binary can find the dll file:
How do I set the path to a DLL file in Visual Studio?

Assimp model loading library install/linking troubles

I'm trying to install Assimp to use in my projects, but I'm having some trouble. I'm currently using win 10 pro and visual studio 15 2017.
I have downloaded Assimp 4.0.1.zip, extracted it into a directory, loaded cmakeGui and ran configuration twice, then generated into Assimp/build directory.
Next I went into Assimp/build and I ran the Assimp.sln and chose the ALL_BUILD I think it was. I then copied all the files in the /code/debug that were alongside the .lib and .dll and moved them all into the Debug directory of my project where my exe is built to. I copied the .lib into my opengl/libs directory and all the headers in /include from the originally extracted download into my opengl/includes/assimp directory.
Finally, I adjusted my projects linker settings to include the assimp.lib and assimp.dll (alias for simplicity of this post)
When I tried to build the project it said it could not open the dll and when experimenting I copied the dll into the project dir alongside main.cpp and my other files and ran again, it this time said "invalid or corrupt file: cannot read at 0x378"
It's safe to say I need to study up on compiling, linking and cmake but for now I started over.
I thought I had it working(and maybe I do...) after I got it to stop complaining when I was including the headers into my project. To do so I started from fresh, built Assimp same as before, moved all the files with the dll into my libs directory, dumped all the includes from the download into my includes, also move the config.h from the build into this directory. Then I set the linker settings in the project and didn't move anything into my project directories.
After that, it stopped complaining so I proceeded with the tutorial series I was following. I compiled, got a load of errors, fixed them down to 0 then suddenly I got 8 new ones in their place.
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _aiGetMaterialTextureCount referenced in function "public: unsigned int __thiscall aiMaterial::GetTextureCount(enum aiTextureType)const " (?GetTextureCount#aiMaterial##QBEIW4aiTextureType###Z) opengl_model_loading F:\Desktop\MyDocuments\Tuts\opengl\getting started\opengl_model_loading\opengl_model_loading\main.obj 1
This error gave me the feeling it was probably due to the dll.
Please advise.
I've just recently done this myself & will say had lot of trouble with v401 & getting errors or linking issues. Successfully got mine working with following;
Note: ASSIMP does have boost as a dependency.
Download/clone master Asset-Importer-Lib from github:
https://github.com/assimp/assimp
Open Cmake GUI & once open:
Where is the Source code: "..\MyDocuments\assimp\assimp-master"
Where to build the binaries: "..\MyDocuments\assimp\assimp-master\build". You will need to make a build folder & point Cmake to it.
2.1. Alternatively if you're familiar with command line option: generate project files with relevant paths using
cmake -G”Visual Studio 14 Win64"
Click configure.
Then Generate. Make sure you select correct build option ie VS15 2017 64bit.
Load "..\MyDocuments\assimp\assimp-master\build\Assimp.sln" with Visual studio.
Right click "ALL_BUILD" & select "Build". This will take several minutes. Once done & no errors, it should create necessary *.dll/*.lib in
..\MyDocuments\assimp\assimp-master\build\code\Debug
Link & include into your existing project the relevant *.lib & also
"..\MyDocuments\assimp\assimp-master\include\assimp" folder. You will also need to make sure *.dll file is in the same folder, or included, as the *exe you're running.
You may also need to copy over from the ..\MyDocuments\assimp\assimp-master\build\include\assimp\config.h" & include it in step7.
Just ensure you're building right libraries for your code ie 32/64bit/debug/release/unicode/etc, otherwise may encounter issues still.
Following video is useful for the visually inclined.
https://youtu.be/W_Ey_YPUjMk
Hope this helps.
EDIT:
If you want static library version ie no .dll required:
From above steps:
5.1. Change relevant project configuration type & extension from .dll to .lib type (should be two: assimp & zlib).
5.2. Right click "UpdateAssimpLibsDebugSymbolsAndDLLs" ->Properties->Build Events & update the paths in the command line sections from ..\Path*.dll to ..\Path*.lib. (If encounter errors, do same on assimp_cmd project).
Same as above but now also need to link your project to IrrXML.lib & zlibd.lib. Should no longer need the *.dll file.

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

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

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.