I am trying to compile the Dlib library in Eclipse, but have an error in linking.
According to: http://dlib.net/compile.html I have to include the path containing the dlib folder (that's what I did) and include the source file in my project: dlib/all/source.cpp.
I keep on getting the following error:
../source.cpp:7:41: fatal error: ../base64/base64_kernel_1.cpp: No such file or directory
This is a line from the source.cpp file. The directory looks like:
/usr/include/dlib-18.6/dlib/base64, If I add that path in my library I get the next error:
In function dlib::threads_kernel_shared_helpers::thread_starter(void*)':
/usr/include/dlib-18.6/dlib/base64/../threads/threads_kernel_2.cpp:37: undefined reference topthread_detach'
Do I have to keep adding paths after each error?
Why doesn't Eclipse just add all subpaths of my /usr/include/dlib-18.6/ (that's the path containing dlib and the it's the path I added)?
I think it depends a bit, on how you had setup your particular toolchain, to build your main/dlib project.
Building using e.g. GCC 4.8 (and using the -std=c++11 option) might require to specify the -pthread option on linking stage, other environments might want to link against -lpthread.
Related
I was trying to install STXXL library to a custom path following this answer supplying prefix to cmake this way:
cmake -DCMAKE_INSTALL_PREFIX=/usr . && make all install
When I run the tests, they seems to be working fine. But I want to include STXXL in a different MakeFile and compile that project. In that MakeFile there a line
STXXL_CONFIG = /opt/stxxl/stxxl.mk
I believe the configuration file stxxl.mk comes from the old make based installation (I couldn't locate it in my system either). I was wondering how I can modify this file to include STXXL library and get the custom project compiled.
Without modifying the above statement in MakeFile, I am getting the error:
undefined reference to 'stxxl::get_next_seed()' collect2: error: ld returned 1 exit status
It goes without saying that I don't have root access and unfortunately, neither a good background with MakeFiles. This is not a duplicate of Makefile with STXXL
To use a third party C++ library from a non-standard location in GNU Make the regular steps are:
Add the path to 3rd-party library headers to your C++ preprocessor flags. E.g.
CPPFLAGS += -I/3rd-party/include
Add the path to 3rd-party shared/staric library to your linker flags and the library itself. Assuming the library is named lib3rd-party.so or lib3rd-party.a, e.g.
LDFLAGS += -L/3rd-party/lib -Wl,-rpath=/3rd-party/lib -l3d-party
As I use a linter that uses gcc I want to include some files from tensorflow into my linter config so that gcc can find them. For some reason it's not very clear to me how I can achieve this. My projectstructure looks like this
Path to my project root dir:
tensorflow/tensorflow/my-classifier
Path to some other c++ .h files from tensorflow:
tensorflow/tensorflow/cc/**
tensorflow/tensorflow/core/**
In my project root dir I have i.e. a file that includes a tensorflow header file like this:
#include "tensorflow/core/framework/tensor.h"
So gcc will somehow search:
PROJECT_ROOT/tensorflow/core/framework/tensor.h
As I use bazel to build, this files will later be included into the build and the compiler will find it without any problem.
But how can I get those files included into gcc for linting purposes?
I tried it using these gcc include flags without any success:
-I../core/**
-I../cc/**
and the absoulte path.
Can someone give me a hint how the right configuration for this would be?
I am trying to install the hep-mc library listed here: https://github.com/cschwan/hep-mc for use on compute using the instructions listed in the documentation here: https://github.com/cschwan/hep-mc#installation . To compile one of the example files, I typed this into the terminal:
g++ -L/usr/local/hep-mc/include vegas_mpi_ex.cpp -o vegas_mpi
but I get these error messages:
mpi_vegas_ex.cpp:1:22: error: hep/mc.hpp: No such file or directory
mpi_vegas_ex.cpp:2:26: error: hep/mc-mpi.hpp: No such file or directory
mpi_vegas_ex.cpp:8:17: error: mpi.h: No such file or directory
in the beginning of my code, the declarations are like this:
#include "hep/mc.hpp"
#include "hep/mc-mpi.hpp"
#include <mpi.h>
The tutorial states that I should point the compiler to the location of the "include" folder that contains all the .hpp files, which I have done. Do you guys have any idea as to what I'm doing wrong?
It should also be noted that the compiler cannot find the mpi.h directory even though I have loaded the openmpi module.
-L sets paths where the linker searches for libraries to link. The option you're looking for is -I, which sets the paths where the compiler searches for #included files.
g++ -L/usr/local/hep-mc/include vegas_mpi_ex.cpp -o vegas_mpi
Oops!
g++ -I/usr/local/hep-mc/include vegas_mpi_ex.cpp -o vegas_mpi
-L specifies the path to library files; -I specifies the path to includes.
This is confusing because in terms of project management and distribution, we consider "the library" to include both binaries and header files, as well as documentation and all sorts of goodies. But at a technical level that is not what "library" means.
I installed OpenBlas and could compile C programs linked to OpenBlas by using
gcc testOpenBlas.c -I /opt/OpenBLAS/include/ -L/opt/OpenBLAS/lib -lopenblas
If I try to link c++ programs using g++ and the same linker options I get the error:
testOpenBlas.cpp:1:28: fatal error: OpenBlas/cblas.h: No such file or directory
#include <OpenBlas/cblas.h>
Any hints?
Here is what I did:
I had to recompile OpenBlas again with g++.
I found that the common.h file exists in the source folder, so I had to include it instead of the installation folder '/opt/OpenBlas'. I still use '-L/opt/OpenBLAS/lib' flag.
Then the problem was solved.
This include directive is looking for the path OpenBlas/cblas.h in all your include directories, in particular also in /opt/OpenBLAS/include/.
So the question is: does there exist a file /opt/OpenBLAS/include/OpenBlas/cblas.h?
Also I think you might have to specify the -I flag before the source file.
Ok, so it's been a while, and i'm having problems with #includes
So I'm doing
#include "someheader.h"
but it's giving me
fatal error: someheader.h: No such file or directory
It's a system wide library I guess you could say.
I'm running arch linux and I installed the library from the repo, and I think the .h files are in /usr/include.
I could just copy all the header files into the folder my code is in but that would be a hack.
What is the "right" way to do this?
Edit: I wasn't correct by saying the .h files were in /usr/include, what I meant was that the library folder was in there
So, Emile Cormier's answer worked to a certain extent.
The problem now is that there are some include in the header file and it seems from the methods I'm trying to access that those includes are not happening
it's giving my the error
undefined reference to Namespace::Class::method()
Edit:
Ok so the final answer is:
#include <library_name/someheader.h>
And compile with
g++ code.cpp -llibrary_name
Sometimes, header files for a library are installed in /usr/include/library_name, so you have to include like this:
#include <library_name/someheader.h>
Use your file manager (or console commands) to locate the header file on your system and see if you should prefix the header's filename with a directory name.
The undefined reference error you're getting is a linker error. You're getting this error because you're not linking in libsynaptics along with your program, thus the linker cannot find the "implementation" of the libsynaptics functions you're using.
If you're compiling from the command-line with GCC, you must add the -lsynaptics option to link in the libsynaptics library. If you're using an IDE, you must find the place where you can specify libraries to link to and add synaptics. If you're using a makefile, you have to modify your list of linker flags so that it adds -lsynaptics.
Also the -L <path_to_library> flag for the search path needs to be added, so the linker can find the library, unless it's installed in one of the standard linker search paths.
See this tutorial on linking to libraries with GCC.
You'd use #include <someheader.h> for header files in system locations.
#include "someheader.h" would try to include the file someheader.h in the directory of your .c file.
In addition to including the header file, you also need to link in the library, which is done with the -l argument:
g++ -Wall youprogram.cpp -lname_of_library
Not doing so is the reason for the "undefined reference .. " linker errors.
The quick fix is to do use:
#include <someheader.h>
assuming that someheader.h is in the standard include locations (to find it use the command locate someheader.h in a shell. If it is in /usr/include it is in a standard location. If it is in a subdirectory of /usr/include you only need to add the part of the directory up to /usr/include in the #include directive (e.g. #include <fancy_lib/someheader.h>)
However, this is only half of the story. You also will need to set up your build system in a way that locates the given library and adds its include path (the path under which it's header files are stored) to the compiler command (for gcc that is -I/path/to/header). That way you can also build with different versions by configuring them in your build system. If the library is not header-only you will also have to add it to the linker dependencies. How this is achieved in your build system is best found out by consulting its documentation.