I'm trying to build an Autotools project using Yocto ADT Plugin and Eclipse Luna.
I need to include some external libraries to the project and to be more specific the boost libraries.
Let's consider the easiest case scenario: header only library.
I should be able to #include into my project.
I'm trying to compile a test code:
#include <iostream>
#include <boost/lambda/lambda.hpp>
using namespace std;
int main(void) {
cout << "Hello World" << endl; /* prints Hello World */
return 0;
}
but I'm getting the error: "fatal error: boost/lambda/lambda.hpp: No such file or directory"
Of course I have to tell the compiler where to find the library.
I tried to do it in different ways but nothing succeded.
To make some examples:
Project -> Properties -> C/C++ General -> Path and Symbols
There I specified the path for downloaded libraries and for compiled libraries (not needed in this case but added for generality):
The include is correctly reported under project explorer but the error persisted.
Then I tried to work on Project -> Properties -> C/C++ General -> Preprocessor Include:
Still getting the same error.
I tried then to include configuring the Autotools adding the -I option:
Of course it didn't succeed either.
After every failed build attempt I run a "Clear Project" and "Reconfigure Project" just to be sure to start all over.
The strange thing is that if I select the boost/lambda/lambda.hpp in the editor and I do "Open Declaration" it finds the file:
At this point I don't know what to do, clearly I'm missing something.
Could you possibly help me ?
Additional Note: If I start an C++ Executable Project using GCC the library is recognized and I have no problems.
So I think the issue is within the Autotools or Yocto ADT.
I even added the boost libraries to my Yocto build and SDK but it's not working.
I managed to succesfully compile adding to the /src/Makefile.am the include to the libraries.
Still I don't understand why this is different from changing the Autotools configure flag.
If someone has an answer, please care to explain.
Related
-- Updates --
Adding the source file settings.cpp directly to the project via Add -> Existing Item resolved the LNK2019 (as I suspected it couldnt find it).
-- Updated Question--
How to specify a source file directory without having to add all the files within it manually as described in the update above? This is clearly achievable for the header files (as described below by adding the directory to the settings, is this not the same for source files?
-- Original Question --
I'm working on replicating a project from CPython into C++ as a challenge to learn more C++ but I can't seem to get the environment established so that I can compile a test run. When I build the solution, it throws a LNK2019 which I know has something to do with the Linker unable to locate the symbols. I have read through numerous solutions on SO that say to updated the properties with the directories of the files, but they do not resolve the issue.
The issues currently stand at:
Some of the headers from other directories show in the explorer, but some do not, why?
The source files are not found and therefore LNK2019 is thrown, cannot resolve, how to?
Here is the layout of my project:
/root
/proj-cmd
/src/main/cpp
/proj/cmd
-> main.cpp
/proj-core
/src/main/cpp/
/proj/cmd
-> command.h
-> base_command.h
-> base_command.cpp
/proj/utils
-> settings.h
-> settings.cpp
The content of main.cpp for testing of environment:
// astro
#include <astro/core/util/settings.h>
// stdlib
#include <exception>
#include <string>
#include <iostream>
using namespace std;
// astro entry point
int
main(int argc, char *argv[])
{
if (conf().hasKey("APP_CWD"))
{
cout << "APP_CWD is: " << conf().getKey("APP_CWD") << endl;
}
else
{
cout << "APP_CWD was not found" << endl;
}
}
In order for #include <astro/core/util/settings.h> to work, I updated the include directories in the properties:
However, in the explorer only command.h and settings.h are shown, not base_command.h:
Additionally, the base_command.cpp and settings.cpp do not display in the source files either, so I updated (similar to the include directories) the source directories:
That takes care of the first issue I am noticing, but now onto LNK2019. I believe this is a related result of the former problem, in that the source files are unknown:
So following many other SO posts, I tried to update the Linker settings without success:
I'm not very familiar with the Visual Studio 2017 environment, so if somebody could provide input as to how to configure these settings so that I can compile I'd appreciate this.
You need to add all .cpp files to your project as Existing Items. Just being in a directory is not sufficient for the IDE to know to compile those files. Headers are found by directory via #include, but you should still add them to your project as Existing Items to make it easier to navigate them in the tree view.
This is why you are getting linker errors: the code in settings.cpp and base_command.cpp are never getting built.
See Microsoft Docs
I am getting a linker error, I'll post it at the bottom. The goal is only to build the example SSL client from boost.
The overall question is just to find the simplest c++ way to download some xml from https://classic.wowhead.com/item=19351&xml
Edit: The problem has evolved as I've continued to work on it. I now realize that I had no idea how to use a static or dynamic library or how either worked. I know a little now.
I've built OpenSSL following this youtube video verbatim and it seems to have built properly. https://www.youtube.com/watch?v=PMHEoBkxYaQ
I'm now using the shorter example https://stackoverflow.com/a/7577229/2247872 and finally got it working which has helped enormously in identifying where the other errors are. I had to be really careful that I was using x86 Debug for everything and then added D:\out\lib\x32\Debug\include to my include directories, d:\out\lib\x64\debug\lib to my linker libraries, and libssl.lib and libcrypto.lib to my additional dependencies. One thing that was helpful is that if #include wasn't underlined by Visual Studio I knew I at least had the include directory set correctly.
I've made two copies of my program, one uses static linking the other dynamic linking. To get the dynamic linking one to work I had to copy the libssl-3.dll and libcrypto-3.dll files in to the same place as my executable.
Right now I'm still fighting with boost on the static one.
#include <boost/beast/core.hpp> //all of these are fine
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <openssl/ssl.h>
#include <openssl/conf.h>
//#include <boost/beast/ssl.hpp> //this line is giving me 196,429 errors.
//#include <boost/asio/ssl/error.hpp> ////this line is giving me 196,429 errors.
//#include <boost/asio/ssl/stream.hpp> //this line is giving me 196,429 errors.
Original Post:
I found similar questions on SO but the names of the OpenSSL libraries have changed and I need a current answer to setting up my MS Visual Studio 2019 project properties properly.
I do not need to build these files (I don't think). All I want to do is get the boost example here https://www.boost.org/doc/libs/master/libs/beast/example/http/client/sync-ssl/http_client_sync_ssl.cpp working.
Question 1: Which of the options from https://wiki.openssl.org/index.php/Binaries or https://slproweb.com/products/Win32OpenSSL.html do I want? For example I don't understand the difference between a pre-compiled build without external dependencies to VS2019 or the one on that bottom pre-compiled build with external dependencies to VS2019. My original choice was the one from the 2nd website that said 1.1.0L "this is the standard version for x64".
I chose the option to install the library files in the Windows System directory. I see files named
c:\windows\system32\libcrypto.dll
c:\windows\system32\libssl-1_1x64.dll
I added C:\Windows\System32 to my path environment in windows and restarted the computer.
In VS project properties:
My C/C++ --> General --> Additional Include Directories are:
d:\cpp\boost_1_72_0
d:\OpenSSL-Win64\include
My Linker --> General --> Additional Library Directories
d:\openssl-win64\lib
d:\openSSL-win64\lib\VC
d:\openSSL-win64\lib\VC\static
c:\windows\system32\
d:\opensll-win64\StaticDLLsIGuess (this is a directory I put files in from a 2nd attempt to solve the problem, by downloading two files from https://indy.fulgan.com/SSL/ but they need in ".a"
d:\cpp\boost_1_72_0\stage\lib
In Linker --> Additional Dependencies I tried to list:
libssl.lib
libcrypto.lib
But when those were there I got a different, simple error saying "libssl.lib" couldn't be found which I found baffling as pretty much my entire computer is in my build options. So why that is happening is question 2. Same thing for
c:\windows\system32\libssl-1_1x64.dll
I know that file is there, but when I put libssl-1_1x64.dll in additional dependencies I get a link1104 error that it's not found even though c:\windows\system32 is in additional library directories.
Question 3 is what libraries do I actually need? There are libraries in my system 32 directory, libraries in D:\OpenSSL-Win64\lib, and libraries in D:\OpenSSL-Win64\lib\VC
This is the actual error I'm getting but I cannot interpret what linker error messages actually mean.
Severity Code Description Project File Line Suppression State
Error
LNK2019 unresolved external symbol _CONF_modules_unload referenced in function "public: __thiscall
boost::asio::ssl::detail::openssl_init_base::do_init::~do_init(void)" (??
1do_init#openssl_init_base#detail#ssl#asio#boost##QAE#XZ) PreparedParser
D:\cpp\PreparedParser\PreparedParser\PreparedParser.obj 1
Edit: I am still in the process of trying to fix this myself, and I'm realizing that part of the problem is that I had no understanding of the difference between a dynamic and static library. I'm trying to figure that out now. Also, https://www.youtube.com/watch?v=PMHEoBkxYaQ is a video on how to compile OpenSSL and I'm doing that.
Edit April 18 11am: Side questions: If I download a .lib from somewhere, how do I put it in my program? Do I #include the lib file? Do I add it to additional dependencies? How do I know what functions are in it? How is it different for .dlls?
I wish to use OpenVDB library in a project. The library has compiled successfully on Windows7 x64 in release version using \MD (as described in https://github.com/rchoetzlein/win_openvdb).
The OpenVDB_cookbook compiles and executes successfully as well. If I put my own code in cookbook, it compiles and executes successfully as well.
But,
If I link the library to an existing project,
or I copy paste the same code (from cookbook) in a new project and use the same cmakelists.txt, Find*.cmake files and all the same options from project properties as from the cookbook,
it throws a linker error 'LNK2019: unresolved external symbols "void_cdecl openvdb::v3_0_0::initialize(void)" referenced in function main'
Even the simplest code of the form:
#include <openvdb.h>
void main()
{
openvdb::initialize();
}
throws this linker error.
Any ideas what am I doing wrong? I am on it for a few days and haven't been able to solve it.
All libraries IlmBase, OpenEXR, glew, glfw, boost and OpenVDB are successfully linked using cmake and are present in the project properties page.
Thank you for the help.
The problem was solved by adding dir\src. and dir\src.. to Additional Include Directories under properties->C/C++->General. Where dir is the directory where the source and build is. I don't know why I had to add this though.
I am currently using Visual C++ 10.0(2010) on a win7 32bit OS.
When I tried to build the basic examples of libigl github tutorials:
libigl tutorials
The following installation code works fine:
#include <igl/cotmatrix.h>
#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <iostream>
int main()
{
Eigen::MatrixXd V(4,2);
V<<0,0,
1,0,
1,1,
0,1;
Eigen::MatrixXi F(2,3);
F<<0,1,2,
0,2,3;
Eigen::SparseMatrix<double> L;
igl::cotmatrix(V,F,L);
std::cout<<"Hello, mesh: "<<std::endl<<L*V<<std::endl;
return 0;
}
which indicates there is basically no problem per the tutorials.
However, I cannot get the tutorial 102 through:
#include <igl/readOFF.h>
#include <igl/viewer/Viewer.h>
Eigen::MatrixXd V;
Eigen::MatrixXi F;
int main(int argc, char *argv[])
{
// Load a mesh in OFF format
igl::readOFF("../shared/bunny.off", V, F);
// Plot the mesh
igl::viewer::Viewer viewer;
viewer.data.set_mesh(V, F);
viewer.launch();
}
After getting a series of building error message of missing some special headers, and then adding the corresponding directory containing the header into the including directory of VS, there is still some header missing which cannot be found in my computer.
Except for the include directory which is required per the tutorial:
x:\Program\libigl-master\include; $(IncludePath);
I already added others as follows:
x:\Program\libigl-master\external\glfw\include;
x:\Program\libigl-master\external\AntTweakBar\src;
x:\Program\libigl-master\external\AntTweakBar\include;
x:\Program\libigl-master\external\glew\include;
Error message is still there:
x:\Program\libigl-master\external\glfw\include\glfw\glfw3.h(163): fatal error C1083: Cannot open include file: 'GL/glcorearb.h': No such file or directory
1>
So I added:
x:\Program\libigl-master\external\glfw\include\GLFW
D:\Program\libigl-master\external\glfw\include\
and got:
x:\program\libigl-master\external\glfw\include\glfw\glfw3.h(163): fatal error C1083: Cannot open include file: 'GL/glcorearb.h': No such file or directo
which does not exist in my computer.
What should I do?
I had the exact same issue, and the thing is that simply adding their include paths won't make it work - as they said it would. That is because LIBIGL itself is just an auxiliary library to help manipulate 3D shapes, but their examples use much more than that (their matrix system comes from Eigen, their graphical system uses GLFW+GLEW, among many others).
But you can get most of the examples working on MSVS setting up the essential libraries. Download the following:
Eigen: This is for the basic matrix/vector arithmetics etc.
GLFW: This is used to create and handle windows for OpenGL.
GLEW: This library has the actual OpenGL function bindings to use OpenGL functions.
Note that these libraries are essential to compile the examples jut because when the examples were made, the creators had the enviroment set up with them (otherwise they would have to code by hand those OpenGL and Windows/Linux windows handling etc. In case you're interested, this is what "pure OpenGL" code looks like). So what you have to do is: set the enviroment for these libraries. This is how to do it:
After creating an empty project in MSVS, go to Solution explorer > right click the project > Properties. You've opened the Property Pages, where all the project configurations are done. We need to specify 3 things: where the compiler can find the headers, the libraries we're using and where it can find these libraries.
First we set up the headers: on the left menu expand C/C++ > General, and on the right, select Aditional Include Directories, click on the down arrow and click edit. A window will open with blank fields, click them twice to add items. Add the eigen header path, the libigl folder path, the glew folder path and the glfw folder path in each line (this is a very confusing interface).
Ok, now we need to specify which libraries we're going to use. Again, in the left menu, go to Linker > Input > Aditional Dependencies (almost the same kind of interface). Add glew32s.lib, glfw3.lib and opengl32.lib (one for each line). Finally, specify where those libraries are. Go to Linker > General > Aditional Library Directories, and specify the path where the downloaded glew32s.lib and glfw3.lib are. (something like "C:\Users...\glfw-3.2.1.bin.WIN32\lib-vc2010") - make sure you're specifying the path to the right compiler - for instance, if you're using MSVS 32 bits 2010 you should select vc2010 and not mingw-64.
If you create a source file in the project using the tutorial 2012 source code it should compile, but you might have to specify the paths to the dll's such as OpenGL32.dll if it's not already in your system path.
Finally, one last thing that might go wrong has to do with something called Runtime Library - it's in C/C++ > Code Generation > Runtime Library. Basically it describes a method to compile code, and each library we're using was compiled using a different one, so we might get errors... Honestly I don't know a lot about that, I just know that mine wasn't working with the default one, so I changed to /MD and it worked. Go figure.
PS: You might as well need to update your graphics card for OpenGL to work.
The only thing that worked for me was creating a visual studio project with cmake-gui. Here is what I did:
Download and install cmake https://cmake.org/download/.
Open cmake-gui.
In 'where is the source code', put the path to the tutorials: .../libigl/tutorial.
In 'where to build the binaries', put whatever your like (I used .../libigl/tutorial/build).
You will also see a bunch of options in red. Select/deselect as desired. I had to deselect Matlab as it couldn't find it for some reason.
Configure and generate (when asked, choose whichever version of Visual Studio you are using).
You should now have a Visual Studio solution in the build folder. Open and build.
I had the same problem in Visual Studio 2013. And the head file I was trying to use was igl/sort.h which cannot be opened.
In the tutorial , they said
Simply add libigl/include to your include path and include relevant headers.
And the include path they were referring here is actually the include directories which can be found under project>properties>Configuration Properties>VC++ Directories, not the Additional Include Directories.
i'm trying to get GMP working with Xcode. So far I have untared the file in the home directory, ran all the necessary commands to have it configure, make, and install
./configure --prefix=/usr/local --enable-cxx
make
make check
sudo make install
Both the gmp.h and gmpxx.h are in the usr/local/include, however I still am getting an error when trying to include the files. I believe I need to add a complier flag but for this version of Xcode I do not know how to do that. If that is not the case and I need to do something else please advise and I would very much appreciate it.
My code looks like the following:
#include <iostream>
#include <gmp.h>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
Can I code with GMP in c++ ? Or do I need code in c? Any help getting this to work would be very much appreciated, thanks a ton in advance!
Sorry if this seems like a DUPLICATE question, i did look at the other questions and I was not able to get it to work following answers from previous questions.
UPDATE
Added the libgmp.la and libgmpxx.la to Xcode, also added /usr/local/include to header file search and it is still not working! I see the library files in my project and if I put "gmp.h" instead of it works but when I go to use GMP it fails telling me to chnange the in other GMP files to "gmp.h" which doesn't seem right.
ANY IDEAS?
this is the fix according to another SO question:
1) Open the left panel,
goto "ProjectName", Targets, Build phases, Link binary with libraries
and select your library.
2) Open the left panel,
goto "ProjectName", Project, Header Search Paths,
write the path where the headers of your library are
(the .h files, usually in /usr/local/include).
3) Open the left panel,
goto "ProjectName", Project, Library Search Paths,
write the path where your libraries are
(the .a or .dylib files, usually in /usr/local/lib)