how to successfully run a c++ file which uses ogdf libraries - c++

I compiled the file (source.cpp) using the command
g++ -I/home/hrishikesh/Desktop/OGDF-snapshot/include -O2 source.cpp -o mytest -L/home/hrishikesh/Desktop/OGDF-snapshot/_release -lOGDF -lCOIN -pthread
and it got compiled successfully without giving any error message,resulting a file "mytest" in the same folder as the source.cpp in.
when I try to run the mytest file using command
./mytest
it shows this error message
./mytest: error while loading shared libraries: libOGDF.so: cannot open shared object file: No such file or directory
please help

You need to put libOGDF.so in the same folder than mytest

g++ -I /AbsolutePath/Desktop/OGDF/ main.cpp -L -l
/AbsolutePath/Desktop/OGDF/_release/libOGDF.a -lpthread
here main.cpp is the file.
copy and paste the line above in other text editors to get rid of the confusions between the usage of I and L and the spaces.
Be sure that you are writing the absolute path correct.
The a.out file will be generated in current directory. execute it by using:
./a.out

Related

G++ build exe file in specific directory

I was lately using SDL and now i want to put the .exe file in a specific directory so it looks cleaner, somebody knows how to do that?
When compiling with g++, gcc, or many other similar compilers, you specify the output file with the -o flag.
For example, to set the output file as foo.exe in the parent directory, you would call g++ like this:
g++ [other options/source files here] -o ../foo.exe

how to run bonmin from a cpp program

I’ve already downloaded Bonmin-1.8.8 and compiled it. The usersmanual said that there is a cpp example in the /bonmin/examples/cppexample.I added the bin and lib to my Path but when I coded
g++ mybonmin.cpp -o mybonmin
It shows that cannot find the headfile. I want to know how can I run Bonmin with the cpp program.
Try passing the flag to the headers:
g++ mybonmin.cpp -I/home/mybonmin -o mybonmin
here more info about it:
-I [/path/to/header-files]

Error message while compiling a program

I’m a newbie to C++ and Linux. There is this code I’m playing with that requires me to install the HElib (Homomorphic encryption library and other libraries - GMP, NTL) which I did. I want to compile the code (main.cpp) that has a header file (FHE.h) in HElib. My problem is how can I link FHE.h (in HElib folder) and main.cpp (in another folder) together so that I can compile them. I have tried some commands
g++ -I/Home/HElib/src/FHE.h main.cpp -o main
Error message
main.cpp:1:17: fatal error: FHE.h: No such file or directory
compilation terminated.
Another command line
g++ -I/Home/HElib/Src/FHE.h -I/Home/SimpleFHESum-master/SimpleFHESum-master/main.cpp -o main]
Error Message
g++: fatal error: no input files
compilation terminated.
What's wrong and how can I fix this?
The -I flag adds the following directory to the include path of the compiler. This enables you to write e.g. #include "FHE.h" even though that file is not located in the same folder as the source file you're trying to compile.
Have you tried just removing the 'FHE.h' part from your -I directive?
g++ -I/Home/HElib/src ...

c++ include directory "file not found"

I'm working on getting an example run for the audioCaffe framework http://multimedia-commons.s3-website-us-west-2.amazonaws.com/?prefix=tools/audioCaffe/
The root directory of this project contains an include directory.
Except, when I navigate to tools and compile g++ caffe.cpp it throws an error:
caffe.cpp:8:10: fatal error: 'caffe/caffe.hpp' file not found
note that include/caffe/caffe.hpp exists
Since you mentioned using g++ caffe.cpp I assume you execute this command form where caffe.cpp file is, which is:
audioCaffe/tools/caffe.cpp
The caffe.cpp file uses #include "caffe/caffe.hpp" which is in the include directory:
audioCaffe/include/caffe/caffe.hpp
So you will need to tell the compiler where to find the headers, you do this with the -I option. Compile it with the command:
g++ -I ../include caffe.cpp

link to an external static library by g++

I am trying to execute a cpp file named "palindrome.cpp" using terminal on my Macbook. This cpp file uses an external library named "libStanfordCPPLib.a" which lies under "DIRECTORY TO CPP FILE/StanfordCPPLib", also the corresponding header files of this library are in this "StanfordCPPLib" folder.
You can see the folder structure by this screenshot:
My code for compiling this source code is :
g++-4.8 -Wall -I/Users/myName/Downloads/CS106B/palindrome/StanfordCPPLib -L/Users/myName/Downloads/CS106B/palindrome/StanfordCPPLib palindrome.cpp libStanfordCPPLib.a
As I understand, -I stands for the directory path where header files exist, and -L stands for the directory path where library (.a file) exists. That's why both -I and -L are the same directory path "/Users/myName/Downloads/CS106B/palindrome/StanfordCPPLib".
However, executing this command returns an error saying :"libStanfordCPPLib.a: No such file or directory". As is shown in the screenshot:
Can anyone see why this happens? Thanks.
Try this, using -lStanfordCPPLib:
g++-4.8 -Wall -I/Users/myName/Downloads/CS106B/palindrome/StanfordCPPLib -L/Users/myName/Downloads/CS106B/palindrome/StanfordCPPLib palindrome.cpp -lStanfordCPPLib