Good day,
I have a file that I'm trying to compile and within it has an #include to a statically linked binary.
#!/bin/bash
g++ -Wall -std=c++17 Message.cpp ../textmagic-rest-cpp/lib/libtextmagic.a
I am getting the following error: fatal error: libtextmagic.h: No such file or directory
The relative path that I provided is correct under the assumption that the current working directory is the directory in which the script is called/ran. I might be linking the binary incorrectly and I've searched around the internet but the other posts/resources did not help me.
Note that the script is run in the same directory as Message.cpp.
g++ has the -I and -L flags that do that for you. Your flag will look like this: -I/ThePathToYourHeaders and -L/ThePathToYourLib. I don't know if g++ supports relative paths there but absolut paths are guaranteed to work there.
Also you probably need to add a linker flag. For your project it will be -ltextmagic. It is just the name of the .a file you want to link with, without the lib in front of the filename.
The #include directive needs to "read" the header file you give it as argument, and that is not included in the static library.
You can either include using a relative path to the source file or pass the location of the header file to the compiler using the -I argument.
Related
i have two folders named Source and powerserver in my home directory. In source direectory i have some code related to project and it uses a .h header file from power server directory. when am compiling using make -f somename.lnx32 I am getting the below error.
error: cst.h no such file or directory.
I am new to this i dont know how to access that .h file ?
GCC looks in several different places for headers. On a normal Unix system, if you do not instruct it otherwise, it will search in default directories.
You can add directories to this list with the -I command-line option. All the directories named by -I are searched, in left-to-right order, before the default directories.
Try gcc -c -I/path_to_powerserver_directory to include header files in GCC search path.
Currently this particular header file is not found to gcc in it's search paths.
It's tagged Linux so i guess you use GCC.
#include <someheader.h> means to search someheader.h in system directories (ie. /usr/include), which you can override using the -Ipath option with GCC.
But in your case, you should be using #include "someheader.h" with the correct user path in your Makefile with the -iquote option.
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.
The libraries that I've used so far require installation. So they generate xx.a file that can be included in the code in cygwin. However, NTL library for windows only requires to unzip the file. So I need to know how to use it in cygwin command line. I have done #include in the code. The problem is in include directory in NTL all files are " .h".
What I have done is:
g++ -c Polynomial.cpp -L/cygdrive/c/cygwin/home/Win7/libpaillier -
l:libpaillier.a -L/cygdrive/c/cygwin/home/Win7/Cryptopp -l:libcryptopp.a -
L/cygdrive/c/cygwin/home/Win7/WinNTL-9_2_0/include/NTL -lgmpxx -lgmp
but I get below error:
fatal error: NTL/ZZ.h: No such file or directory
#include <NTL/ZZ.h>
^
compilation terminated.
It'd be great if someone give me a clue. TBC: I have already installed GMP and been using it.
In gcc path to headers location is specified with -I switch. With -L you define paths to compiled libraries location (directories with .a or .so files).
Also if full path to zz.h is /cygdrive/c/cygwin/home/Win7/WinNTL-9_2_0/include/NTL/zz.h then NTL should not be included in path specified in gcc arguments.
So, you need at least to replace
-L/cygdrive/c/cygwin/home/Win7/WinNTL-9_2_0/include/NTL
with
-I/cygdrive/c/cygwin/home/Win7/WinNTL-9_2_0/include
and maybe for others libraries as well and add paths to compiled libraries locations with -L where they are needed.
When I use type make into Ubuntu terminal I get:
main.cc:5:30: fatal error: folder/file.h: No such file or directory
The folder exists in the working directory and the file.h exists in the specified folder.
When I type ls it lists the folder and file in my working directory as well.
Oddly enough, when I open it in geany and ask it to find the file in the
#include <folder/file.h>
it finds it without issue but when it builds it I get the error.
Is there a flag I need to set so it so it includes the folder? If so, what would that look like exactly?
This depends a bit on your C compiler, but "typically" when you include a file using the < ... > syntax the compiler will only look for those header files in directories you have specified on the command line with the -I flag, plus various built-in system directories.
Notably, it usually will not look in the current working directory, unless you explicitly add -I. to the compile line.
Alternatively, if you use the " ... " form of #include, then it will look in the current working directory as well.
So, either switch to #include "folder/file.h", or else add -I. to your compile line.
You need to use quotes instead of <> for the include, this makes it that the compiler searches in the source file's directory first:
#include "folder/file.h"
Alternatively explicitly add the current directory to your include paths
g++ c -I. main.cc
Regarding you question, I think first you need tell the compiler, where is you head file, since you write your code as:
#include <folder/file.h>
I assumed that you store your file.h in $you/include/path/folder, therefore, you need pass -I ${your/include/path/} to compiler like:
gcc -I${your/include/path/} ...
be aware, you specified in your code the include as <dir/file.h>, I think this kinds of define show following idea:
$main_include_path
|
+----folder1
|
+----folder2
|
.
.
.----folderN
Then, you can ONLY write makefile to specified the include path to it father
Hi i would like to include a external library call NTL. its in the path as followed:
#include "WinNTL-5_4_2/include/NTL/tools.h"
My file is key.cpp and its reside in the same folder as NTL . but when i compile, it came up with another error which is ..
In file included from keygen.cpp:6:0:
WinNTL-5_4_2/include/NTL/tools.h:5:24: fatal error: NTL/ctools.h: No such file or directory
compilation terminated.
As its need another file call ctools.h, how do i includes tools.h to make ctools.h work also
I tried type
me#ubuntu:~/GG$ g++ keygen.cpp -o keygen -l WinNTL-5_4_2/include/
keygen.cpp:6:23: fatal error: NTL/tools.h: No such file or directory
but it doesnt work still.
Based on the error message, you should try changing your include to:
#include "NTL/tools.h"
and make sure that WinNTL-5_4_2/include is in your compiler's search path for include files.
You need to add the root directory as part of your project's search path for include files. It depends on your environment exactly how to do this, but there are usually two search paths -- one for include files and another for compiled libraries. Set that with the directory that contains the WinNTL-5_4_2 directory and you should be golden.
You had to add "fullpath/WinNTL-5_4_2/include" in you include path of your compiler (either by -I for gcc or in the include path list of a visual studio project)
Expecting that ctools.h exists in ".../WinNTL-5_4_2/include/NTL"