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.
Related
Hi everybody I recently created a C++ project in which I put my code into header.h and header.cpp files and successfully create a static library called header.a. Now I put my header.h file into /usr/local/include position of my system and header.a into /usr/local/lib in order to "install" my library into the machine. Now, if I want to use this library, I have to do the following steps:
Suppose I am using a main.cpp program, I include this line at the top of the program:
include <header.h>
Then, I compile with this command:
g++ main.cpp /usr/local/lib/header.a
And all it's ok. But I want to find a way to "store" permanently the header.a library into the system in order to use it like a normal standard C++ header, simplifing the compilation in this way:
g++ main.cpp
Is there a way to do this? Many thanks to all.
You can't, and no system library will be linked automatically without being told to do so.
You can however add the path /usr/local/lib to the default paths for the linker to look for libraries (IIRC it's not in there by default for Ubuntu), which means you only need to add the -l (lower-case L) option to link with the library.
But do note that the library should be having a lib prefix. Like in libheader.a.
Then link with -lheader:
g++ main.cpp -lheader
There also the -L option to add a path to the list of paths that the linker searches, if you have other non-standard paths, of if you can't edit the system configuration to use /usr/local/lib:
g++ main.cpp -L/usr/local/lib -lheader
The library file still needs the lib prefix.
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.
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.
i just started with c++ programming.
For my new work, i have to download, install and take use of an external library. It is called ICE.
It was composed as a .tar file, so i decomposed it inside my home-directory "/home/foo/ice".
Now, there is the directory: "/home/foo/ice/src", within all the .h headers, i need for the program.
But can i tell the compiler, where he can find all these new headers?
I mean only with #include, he obviously doesn't know.
What i need:
#include <image.h>
"image.h" is inside "/home/foo/ice/src"
Greetings
If you have gcc compiler you can use -I option.
From the manual :
-I dir: Add the directory dir to the list of directories to be searched for header files.
So for you it should be something like this:
g++ myprog.cpp -I /home/foo/ice/src -o myprog
But it is better to install the library, you should have some readme.txt or INSTALL file about how to do this..
You asked about linking a library, but your description shows that you have problems with the include path, which klm123 answered already.
The library paths for linking is another option, usually -Llibpath
It may help to check the options of you compiler, here for example the Directory Options of GCC