I have a simple c++ program. Its not even doing anything, just includes mysql.h.
I compile with this command: g++ -o main main.cpp -I/usr/include/mysql. The include path is correct, thats where mysql.h is. It says no such file or directory and i don't know why.
Related
I'm trying to compile a C++ file on a Mac that uses opencv2.
I downloaded opencv, found an opencv2 folder in it, and copied it into the folder where main.cpp (the program I'm trying to run is).
The folder structure is:
main.cpp
BRIEF.h
opencv2
core.hpp
core
cvdef.h
My current command (after reading this and this) is g++ -I/opencv2/core.hpp main.cpp, run from within the same folder main.cpp is in.
main.cpp has #include "BRIEF.h" which works fine.
BRIEF.h has #include "opencv2/core.hpp" which works fine.
core.hpp has #include "opencv2/core/cvdef.h" which fails saying the file was not found.
How do I use G++ such that the file can be found?
As you said, you are only including this file/opencv2/core.hpp so it is normal that the compiler fails finding the other files.
In your code you are including your files starting from your project root directory, so you have to include the project root directory for the compiler to find these files:
g++ -I$(PROJECT_DIR) $(PROJECT_DIR)/main.cpp
or if you run g++ from the root directory, you can use ., which will expand into the current path (your project root directory):
g++ -I. main.cpp
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 ...
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
I am new to C++ programming and trying to add a library (Yepp) to my cpp file.
I am trying to compile and it says it cannot find a header file from the external library. The external library, yeppp, has a .so file which I placed in a lib folder in the root directory.
I am building with the following command:
clang++ -O3 test.cpp -o test -L lib/ -lyeppp
Here's the error:
test.cpp:7:10: fatal error: 'yepCore.h' file not found
#include <yepCore.h>
You need to tell the compiler where to find the header file. Use the -I option.
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