Compile c++ file using external library from linux terminal - c++

I have the following files:
ex1.cpp ex1.h
GLee.cpp GLee.h
and I want to make it use the library (openmesh library) on the following path:
home/xyz/Downloads/OpenMesh-2.3/src/OpenMesh/
I'm trying to execute it with this:
g++ -Wall -o ex1 ex1.cpp GLee.cpp -L/..path../
but no luck, output is:
In file included from ex1.cpp:17:0:
ex1.h:28:38: fatal error: OpenMesh/Core/IO/MeshIO.hh: No such file or directory
compilation terminated.
what is the correct way of doing this?
Thanks!

You need to put -I path on the command line. So from the error, it looks like you would do:
g++ -Wall -o ex1 ex1.cpp GLee.cpp -I /home/xyz/Downloads/OpenMesh-2.3/src

Related

G++ compiler not recognizing SQLAPI.h header file

I'm trying to compile a C++ program on my MacBook CLI using:
g++ -o -I/Users/user/SQLAPI/include/SQLAPI.h program driver.cpp
but getting the error:
driver.cpp:3:10: fatal error: 'SQLAPI.h' file not found
#include <SQLAPI.h>
^~~~~~~~~~
I placed the download from https://www.sqlapi.com/Download/ into directory /Users/user/SQLAPI/. I've confirmed that the SQLAPI.h file is in /Users/user/SQLAPI/include/SQLAPI.h, so I'm confused as to why my g++ isn't recognizing the header file. Please help!
The argument for -I is the directory to search for the headers.
The argument for -o is the output file name.
You most probably want to:
g++ -I /Users/user/SQLAPI/include -o program driver.cpp
Which of course most probably will solve only the current include problem and will not link with SQLAPI library.

fatal error: google/protobuf/port_def.inc: No such file or directory #include <google/protobuf/port_def.inc>

I have windows. And I want to create an C++ op using library tensorflow. From this site https://www.tensorflow.org/guide/extend/op#compile_the_op_using_your_system_compiler_tensorflow_binary_installation I understood that I should do folowing:
TF_CFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') )
TF_LFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') )
g++ -std=c++11 -shared zero_out.cc -o zero_out.so -fPIC ${TF_CFLAGS[#]} ${TF_LFLAGS[#]} -O2
I did that. But I got next problem:
In file included from C:\Python\Python37\lib\site-packages\tensorflow\include/tensorflow/core/framework/op_def_builder.h:24,
from C:\Python\Python37\lib\site-packages\tensorflow\include/tensorflow/core/framework/op.h:23,
from zero_out.cc:4:
C:\Python\Python37\lib\site-packages\tensorflow\include/tensorflow/core/framework/op_def.pb.h:10:10: fatal error: google/protobuf/port_def.inc: No such file or directory
#include google/protobuf/port_def.inc
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
I don't understand how can I solve this problem. I would be really grateful if you can help me to solve this problem
I think you might have solved the problem by now, but for the reference of others posting one possible solution. Find the tensorflow include directory path and include it while compiling your code. You can manually check that the header file (missing in your case) is present in the include path.
tf_include_dir=($(python -c "import tensorflow as tf; print(tf.sysconfig.get_include())"))
and modify your compile command to include the tf_include_dir i.e.
g++ -std=c++11 -Itf_include_dir -shared zero_out.cc -o zero_out.so -fPIC ${TF_CFLAGS[#]} ${TF_LFLAGS[#]} -O2
I use a simple way, whenever make fails:
make clean
make all -j 16

the g++ command returns no such file or directory

I am new to programming; I'm starting a new job and I have to resume what the fellow before me did.
So I have to run a program called test.cpp in C++. This code contains a header called misc.hpp located in a subfolder of where test.cpp is called include.
When I open the terminal from where test.cpp is and run g++ test.cpp it tells me that:
test.cpp:4:19: fatal error: misc.hpp: No such file or directory.
I also tried the g++ test.cpp -I include/misc.cpp but same thing
Could you please help me?
The -I (upper-case i) option is to add a directory to search for header files. It's not for including source files.
So if the header file is include/misc.hpp then you should do
g++ test.cpp -Iinclude
-I include/misc.cpp doesn't work because:
The file is misc.hpp, not misc.cpp
You do not include files like this
-I is for include directories
So:
g++ test.cpp -I include

Geany, g++ and SDL errors in compilation

So, I was following a simple C++ with SDL tutorial for linux but i encounter some errors on my way.
First of all I'm using Geany and i downloaded the corresponding SDL2 libs, here is the thing:
in my project folder there is a main.cxx file, which i open with geany as i mentioned before:
I included this libraries:
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
First i encountered a pelculiar error, compilation performs sucessfully but when it comes to build i got this error:
main.cxx: undefined reference to `SDL_Init'
After searching a bit i found out that i had to add the tag -lSDL to my geany build options so they would end up being somethinf like this:
Compile:
g++ -Wall -c -lSDL "%f"
Build:
g++ -Wall -o -lSDL "%e" "%f"
But there is a problem, now when I execute the build command i get a:
G ++: error: main: There is no such file or directory
Why am i getting this error, am I including a wrong library or g++ has problems with .cxx files?
I already tried converting between .cxx and .cpp.
Thanks in advance.
g++ -Wall -c -lSDL2 "%f"
There is absolutely no need to specify libraries during compilation phase. Remove -lSDL.
g++ -Wall -o -lSDL2 "%e" "%f"
It invokes compiler, implies linking (no -c or other operation-specific flags), and sets output file name to -lSDL2. That is, linker will output resulting binary in a file named -lSDL2 in current working directory. Then, when it comes what files to link, it goes main, which supposed to be -o main, but since you've broken flags order it is now just ordinary file name that linker will try to link into resulting binary. It so happens that this file doesn't exist.
Long story short, make correct linking line - g++ -o "%e" %f -lSDL2 (libraries comes last, library order is also important).

MINGW, Code::Blocks - No such file or directory error when compiling c++

When I try to compile C++ programm in Code::blocks it gives me this error:
-------------- Build: Debug in elcounter (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Weffc++ -Wall -std=c++14 -fexceptions -Weffc++ -std=c++14 -g -I"C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\" -c "C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe: error: Sync\CPP: No such file or directory
mingw32-g++.exe: error: projects\September_2k16\elcounter\main.cpp -o obj\Debug\main.o: No such file or directory
mingw32-g++.exe: fatal error: no input files
I am using MinGW g++ compiler.
Just for a test, I tried to compile simple "Hello, world" file and it gave me the same error.
Compiled the same "Hello, world" file in a command line using
"g++ test.cpp -o hello.exe" and in worked just fine, so I believe the compiler is installed correctly.
The error seems to be related to spaces in a file path.
C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\
mingw32-g++.exe: error: Sync\CPP: No such file or directory
mingw32-g++.exe: error: projects\September_2k16\elcounter\main.cpp -o obj\Debug\main.o: No such file or directory
Might be a problem with a build system in Code::blocks? I tried to copy the command code::blocks using to a command line and it gave the same error. (mingw32-g++.exe -Weffc++ -Wall etc.)
EDIT: I don't want to change file path because "Box Sync" is used by the same name app that synchronizes file with a cloud.(box.com) The app doesn't support changing the main folders name and I'd prefer the project files stay synchronized.
Looks like you need to remove all spaces from file and folder names in your project.
In your case it's the 'CPP projects' folder and 'box sync'