Problems linking Nlopt-2.4.2 in visual studio 2017 - c++

Some back story: I am trying to get the bolt-lmm software to compile on a Windows machine, because it would be a nice addition to the research group I am in. The developers of the software have only made a linux static executeable, but made the source code available. I am used to programming in R or python, and this is my first ever encounter with C++.
I have solved a fair bit of problems, but for some reason I have not been able to get visual studio to link properly with Nlopt-2.4.2.
I downloaded it
and followed the steps given there on how to install it.
I can tell I have done the same to link the Nlopt library to the project as is described in How to add additional libraries to Visual Studio project?
I still get errors like:
Error LNK2019 unresolved external symbol __imp__nlopt_create referenced in function "public: __thiscall nlopt::opt::opt(enum nlopt::algorithm,unsigned int)" (??0opt#nlopt##QAE#W4algorithm#1#I#Z) boltCompiler C:\Users\au483192\source\repos\boltCompiled\boltCompiler\NonlinearOptMulti.obj 1
(there are a total of 12 of this type of error, and an error link 1120, which just tells me there are 12 unresolved eternals.)
I hope this is enough information to provide a hint of what is going wrong.

I did some more digging, and it seems the linker needed more than just the folder for the .lib file.
This post sums it up:
Linking a static library to my project on Visual Studio 2010
Essentially you just need to tell the linker the placement of the lib and the actual name of the .lib file.
Hopefully this will help others who forgot/did not know that added library names manually could be needed for some libraries.
TL;DR:
open configuration properties for the project > linker > general
Then add the path to the .lib file in the "addition library directories" line
Then (still in configuration properties) go to linker > input
add the .lib file name to the "addition dependencies" line, e.g. libnlopt-0.lib (don't forget to separate with ";")

Related

How to use libpng in Visual Studio?

I am using boost generic image library and it requires libpng. I built libpng and obtained the files libpng.lib, zlib.lib and libpngd.lib. When I tried to compile my project, Visual Studio gives a fatal error
fatal error LNK1120: 21 unresolved externals
with a bunch of unresolved external symbols like _png_set_sig_bytes and _png_read_row. What's going on here and how to solve it?
From MSDN:
https://msdn.microsoft.com/en-us/library/ba1z7822.aspx?f=255&MSPPError=-2147217396
To add .lib files as linker input in the development environment
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
Click the Linker folder.
Click the Input property page.
Modify the Additional Dependencies property.
You must do this; explicitly specifying "libpng.lib", "zlib.lib" and "libpngd.lib" in your .exe's link command.
So this is coming from a complete simple minded moron so maybe this'll be helpful....it took me a little while to grasp. Basically, you're downloading the source code. That means, that you have to be the one to compile the source code.
Windows can compile programs that are written in C in the command prompt. You have to build the program, and it spits out a .dll or a .lib file. That or those are the files that you link to visual studio application.
You set dependencies to the header files which is usually like the source codes root folder or wherever all those .h files are.
You then set the linker to link to the .dll or .lib file(s). In Boost C++'s case, you need to link to a 'lib' folder.
I think what you need is to go over and completely grasp the basics. Here's a link from Microsoft on how Windows can compile C programs from the command prompt:
https://learn.microsoft.com/en-us/cpp/build/walkthrough-compile-a-c-program-on-the-command-line?view=vs-2019

Linking a DLLs in visual studio 2013

I've already looked for solution, without a success.
I need to use a DLL supplied by third parties on Visual Studio 2013(running on (x64) Windows 10).
On machine there are both OpenCV 3.0.0 and OpenCV2.410 installed and working.
The DLL's author has provided a .lib file and He says that in order to use this DLLs in your project, you need to put some others OpenCV's dlls in the project folder( I've tried to put these DLLs in every project folder[yes I know, it has no sense, but after a lot of tries i've lost my patience])
What he supplies is an .dll and an example project( that doesn't work for me because it needs OpenCV2.1 and there are instructions needs to be translate in newest version [and I prefered don't translate nothing]).
The errors in this example project are of this kind:
error LNK2001: unresolved external symbol
fatal error LNK1120: unresolved externals
The most of them are caused by the miss of OpenCV2.1, that I don't want to install, because I'll have to use it on a program using with OpenCV 3.0.0.
In the example project folder there are:
The upper mentioned .dll
A .lib file
The header file .h
These DLLs: cv210.dll, cxcore210.dll, highgui210.dll, ...(eg. cv210d.dll)
What I've done is this:
A folder called "lib" where I insert all .dll, .lib, .h files.
Put the "lib" folder in Project properties>linker> General> Additional Library Directories
Writing the .lib file in properties>linker> Input> Additional Dependencies
Put the 'lib' pathproperties>C/C++>Additional Include Directories[I know, this has no sense too]
I get these kind of errors:
error LNK2001: unresolved external symbol
I've tried #pragma comment(lib, 'file.lib') way too.
Someone can help me?

Linking DLL error visual studio

I walked through this tutorial and tried to recreate the example I get this error:
Error 1 error LNK2019: unresolved external symbol __imp__GetXyz#0 referenced in function _main app.obj app
If I download the source from the website and run the project in visual studio it works, but If I even copy the code from the original project in my own visual studio solution it still doesn't work. I guess it must be some project settings, I don't know. What do do?
You need to add the XyzLibrary.lib to your Linker settings within project settings.
You can also do it directly in code by using #pragma comment(lib,"xyzlibrary.lib") if you are using VisualStudio.
The reason why it works in the given sample without these 2 approaches is that in the solution file, the dependencies are set from XyzExe to XyzLib, and XyzProject has 'Link Library Dependencies' in Linker settings set to true. However, I am not too keen on this approach, as I don't like to store data important for building inside solution files (for larger projects, developer's solution files can differ from build system solution files)
Seems like you are missing some external library that needs to be linked in. Whatever provides the GetXyz function is missing.
Open the Solution that works, right click the project, Properties, Linker, Input, and check what their Additional Dependencies list up. You need to add the same to your own project.

Installing LibCurl on Visual Studio 2010

I've been having a bit of trouble using LibCurl with Visual Studio 2010. Keep in mind I'm pretty new to C++.
I built the library according to the instructions on the libcurl website and tried to point my project to the include directory, libcurl.lib, etc but when I try to build the project I get a bunch of LNK2019 errors.
Can someone please walk me through how to tell Visual Studio where the include files, .lib file, etc are (i.e. all the steps after building LibCurl up to using sample code in a test project)?
Thanks in advance.
error LNK2001: unresolved external symbol __imp__send#16
Hurray, we have an error message. Add ws2_32.lib to the Additional Dependencies setting. The MSDN Library lists the required import library at the bottom of the article for each API function.
Interpreting the linker error is important to diagnose these errors. Ignore the __imp__ prefix, that's linker glue. You can tell it is trying to find the definition of the send() function. That's a standard socket API function. The MSDN Library article for send() told me you need to add ws2_32.lib to the dependencies. The article is here, scroll to the bottom. This same information should also be available in the library documentation.
open the project settings dialog window first (right click >> properties)
this contains everything in regards to getting the project configured
find "Linker", then expand it and go to "Linker >> General"
under "Additional library directories" add the location of the ".lib" files
then go to "Linker>>input" and add the name of the library files you want to include

How to add MySQL connector/C++ 1.1 to Visual Studio 2010 project?

I'm trying to add MySQL Connector/C++ to my visual Studio 2010 project.
I followed the steps (here, mysql docs) to add it to Visual Studio (I also added Boost in the "Additional include Directories").
It asked for a "sqlstring.h" file ( How a release can miss a file ?! ), so I had it from the source files (mysql source archives).
Then, It asked for libmyql.lib, I had the lib directory of MySQL Server 5.5\lib.
And now, I'm on this error:
Error 127 error LNK1120: 31 unresolved externals C:\Users\Haks\Documents\Visual Studio 2010\Projects\ProductManager\Debug\ProductManager.exe ProductManager
Error 60 error LNK2001: unresolved external symbol "__declspec(dllimport) bool __cdecl std::operator<<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??$?MDU?$char_traits#D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0#0#Z) C:\Users\Haks\Documents\Visual Studio 2010\Projects\ProductManager\ProductManager\mysqlcppconn-static.lib(mysql_ps_resultset.obj) ProductManager
So, maybe it's because I got the binary release of MySQL Connector/C++ 1.1 and maybe it's not compatible with VS 2010...
But I don't find the good way to compile the source files, and I never use Boost or CMake and it's seem to be needed.
I found no reference to my problem, so if someone got a response or a good way, it will be very useful for me and a lot of people I think.
Thank you
First of all, thanx to the dar7yl for pointing in the right direction.
After spending much time debugging mysql connection (VS 2010, C++), which proves to be a much hair raising experience, I am compelled to say something about it.
(assumed you setup C++ include files directory and link directory + additional dependence file correctly, else refer to the website on point 2 for reference)
0.) Yes, we need boost library. Download boost library (search google) and unpack it into your development folder and have your c++ additional include directories point to it(boost main directory, not the boost child directory).
1.) Need to be clear on the difference in VS solution configuration mode "debug" and "release". The .lib files provided provided after full installation of MYSQL under directory ...\mysql\Connector C++ ____\lib\ has two directories of debug and opt for use with solution mode "debug" and "release" accordingly. The main difference being "debug" mode uses the extra .pdb files.
2.) http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-apps-windows-visual-studio.html gives a very detail outline for VS2008 mysql connection setup. Particularly the need to include under [Project, Properties tree view, under C++, Preprocessor] two statement of CPPCONN_PUBLIC_FUNC= and HAVE_INT8_T=1
3.) be clear which mode of connection you would like with the library, mysqlcppconn.lib is dll based while mysqlcppconn-static.lib is static based. For dll based lib, related dll mysqlcppconn.dll needs to be deposited into \windows\system32\ or other system path for access.
For static connection remember its using extern C connection so you will need libmysql.lib + libmysql.dll (libmysql.pdb if under "debug") from ...\mysql\connectorc c ___\, if not you will get the unresolved external symbol error LNK 2019. So promptly update your c++ include files directory, link include file directory, additional dependency accordingly and deposite the .dll file into system path or ....\windows\system32\
4.) At this point, things should work for some of us. And no, it didn't work for me. Reason? Library comparability issue as outlined by dar7yl. So if this is the case, download source code for the connector under http://dev.mysql.com/downloads/connector/cpp/ by select platform to source code. Unpack and it get a bit complicated from here.
No VS solution or project files? No worries, see the cmake__.txt file? that's our solution.
Download cmake and have the source directory and destination directory point to your unpacked source code directory. Then open cmake__.txt in the directory and search for keyword "boost" and update the boost directory to point to your boost directory. Run configure and set to VS 2010, check the outlined configuration and change whatever is necessary Name/Value table then press generate.
By now your project + solution files should have been generated, open it and you will see many projects. We are only concerned with mysqlcppconn and mysqlcppconn-static. check and update the include files, link files + dependency in the two project's property and compile. Drop the generated .lib + .dll (and .pdb if using "debug" mode) into the corresponding directories and your project should work now.
By this point mysql connection now works for me, hope it works for you too. Some details might be missing from the above and I do apologies.
Just a small addition to dddddd great post. If you are compiling on Windows7 then you will probably get some 'unresolved externals' from the libmysql.lib library. I found this was due to the fact that the libmysql.lib came from a 64bit installation of the server. You will need to find the 32 bit version and link with that, or just install the 32 bit server instead.
I finally got MySQL Connector/C++ working with visual Studio 2010 by downloading the source and compiling it with the same settings as my project. It still warns about SqlString library:
j:\mysql-connector-c++-1.1.0\cppconn\sqlstring.h(36): warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLString'
but, it seems to be ok with that.