G++ -I option for compiling program - g++

Here is a little problem that cannot be resolved by me such a Linux program newbie.
Now I have a main.cpp program which need to be compiled, there is a
#include "Down.h"
in the front of file.
Actually, this header file exist in the other directory, which locates at
../../../include
directory. Besides, some other header files needed by Down.h also locate at this ../../../include directory.
Here is the problem, I compile main.cpp with command
g++ -I /../../../include main.cpp
However, it gives lots of error info which means it is not correct to be done like this.
Should I also change the include declaration into this one?
#include "../../../include/DownConvert.h"
May you please leave me with some advice? Thanks.
Edit:
After using g++ -I ../../../include main.cpp, I get the following errors:
$ g++ -I ../../../include main.cpp
In file included from ../../../include/DownConvert.h:98,
from main.cpp:92: ../../../include/ResizeParameters.h:4:22: error:
TypeDefs.h: No such file or directory
In file included from /usr/include/c++/4.4/bits/stl_algo.h:61,
from /usr/include/c++/4.4/algorithm:62,
from ../../../include/H2

g++ -I /../../../include main.cpp
See that leading slash after the -I? That's an absolute path.
Change it to a relative path (shown below) and it'll work OK.
g++ -I ../../../include main.cpp

g++ -I ../../../include main.cpp
ought to work

Try to use -v option:
g++ -v -I ../../../include main.cpp
And check that list of directories to search for include files contains your folder and there is no complains that this folder is absent. If there is this sort of complains correct the path that you give after -I

Related

How to use g++ without Makefile to build cpp that makes calls to other header files?

I am trying to build at the command prompt the following:
g++ -c ../../TRUNK/StringUtl.cpp -o StringUtl.o // ok
g++ -c ../../TRUNK/CircularBuf.cpp -o CircularBuf.o // ok
g++ -c ../../TRUNK/UartComm.cpp -o UartComm.o // fatal error: CircularBuf.h: No such file or directory THE header to his cpp file has #include "CircularBuf.h"
UartComm.h: contents at the top of file
//---------------------------------------------------------------------------------------
// General inclusions
//---------------------------------------------------------------------------------------
#include <stdio.h>
#include "CircularBufClass.h"
This error is beacuse g++ is not able to find the header files. You would need to provide path of your header files using -I<Path> option.
Eg:
g++ -Iyourheaderfilepath/ -c ../../TRUNK/UartComm.cpp -o UartComm.o

Changing parameters for include files with CMake

I'm trying to set up a toolchain for CMake and have made some progress (it's getting the right compiler and all), but I've run into a problem with the -I (include directories directive).
The compiler I'm using doesn't understand -I, it understands -i. What I don't understand is where to change this so that CMake builds the makefile with the -i rather than the -I.
Any help would be greatly apprecaited
Somewhere in your CMakeLists.txt file, you should add the following line:
set(CMAKE_INCLUDE_FLAG_C "-i")
This will change your include flag from the default of -I to -i. Do CMAKE_INCLUDE_FLAG_CXX for C++.
I say this with the caveat that you might want to wrap this in a if that only does this for the Cosmic compiler.
CMake sets this to -I by default in the file CMakeGenericSystem.cmake... search your cmake install dir this file and you will see the CMake defaults for several settings inside. If a compiler has to modify this, it will be in the Compiler folder in the same dir as CMakeGenericSystem.cmake. I'm willing to bet that there is nothing implemented in the Compiler folder for the Cosmic compiler.

MinGW linking dynamic library with bad name

I am using MinGW64 (Windows 7) without MSYS and I have the following problem:
I have one dll, written in C99, which has to have the .mexw64 suffix so it can be used by Matlab. I would like to be able to link this dll form another dll (mexw64) dynamically but gcc won't allow me to link directly. I cannot do static linking, because both dlls have many functions of the same name which can be hidden by not exporting their symbols when creating the shared library.
So far, I have tried:
To create a symbolic link (with correct suffix and preffix) using mklink. This works, but I was not able to run mklink from the makefile. Maybe it is due to the fact I am not using MSYS which could have ln -s (I havent checked).
To do the copy of the first dll and correcting the suffix and prefix. This worked better than I expected, because on runtime the second dll actually uses the original .mexw64 and not the dll copy. I guess it is just because the .mexw64 is found first, but why is that .mexw64 searched in the first place? How the system know it is actually a dll?
My question is, is this correct/safe enough? Are there any other options?
Thanks for comments.
You should build a proper implib, either as a linker output or from a .def.
Linker:
$ gcc -shared -o testimpl.mexw64 testimpl.c -Wl,--out-implib,libtestimpl.a
$ dlltool -I libtestimpl.a
testimpl.mexw64
Or create a .def file, specifying an explicit LIBRARY:
$ cat testimpl.def
LIBRARY testimpl.mexw64
EXPORTS
test #1
$ dlltool -d testimpl.def -l libtestimpl.a
$ dlltool -I libtestimpl.a
testimpl.mexw64
And finally, link stuff:
$ gcc -o test.exe test.c libtestimpl.a
# or
$ gcc -o test.exe test.c -L. -ltestimpl
$ grep testimpl.mexw64 test.exe
Binary file test.exe matches

Unbound modules in OCaml

My problem is that ocamlc and ocamlopt apear to be refusing to find third party libraries installed through apt-get. I first started having this problem when I tried to incorporate third-party modules into my own OCaml programs, and quickly wrote it off as a personal failing in understanding OCaml compilation. Soon-- however-- I found myself running into the same problem when trying to compile other peoples projects under their own instructions.
Here is the most straight-forward example. The others all use ocamlbuild, which obfuscates things a little bit.
The program: http://groups.google.com/group/fa.caml/msg/5aee553df34548e2
The compilation:
$ocamlc -g -dtypes -pp camlp4oof -I +camlp4 dynlink.cma camlp4lib.cma -cc g++ llvm.cma llvm_bitwriter.cma minml.ml -o minml
File "minml.ml", line 43, characters 0-9:
Error:Unbound module Llvm
Even when I provide ocamlc with the obsolute paths to the llvm files, like so...
$ ocamlc -g -dtypes -pp camlp4oof -I +camlp4 dynlink.cma camlp4lib.cma -cc g++ /usr/lib/ocaml/llvm-2.7/llvm.cma /usr/lib/ocaml/llvm-2.7/llvm_bitwriter.cma minml.ml -o minml
... to no avail.
What am I doing wrong?
Your command is doing two things: it's compiling minml.ml (into minml.cmo), then linking the resulting object into minml.
Compiling a module requires the interfaces of the dependencies. The interfaces contain typing information that is necessary to both the type checker and the code generator; this information is not repeated in the implementation (.cma here). So for the compilation stage, llvm.cmi must be available. The compiler looks for it in the include path, so you need an additional -I +llvm-2.7 (which is short for -I /usr/lib/ocaml/llvm-2.7).
The linking stage requires llvm.cma, which contains the bytecode implementation of the module. Here, you can either use -I or give a full path to let ocamlc know where to find the file.
ocamlc -g -dtypes -I +camlp4 -I +llvm-2.7 -pp camlp4oof -c minml.ml
ocamlc -g -cc g++ -I +camlp4 -I +llvm-2.7 dynlink.cma camlp4lib.cma llvm.cma llvm_bitwriter.cma minml.cmo -o minml
or if you want to do both stages in a single command:
ocamlc -g -dtypes -cc g++ -I +camlp4 -I +llvm-2.7 dynlink.cma camlp4lib.cma llvm.cma llvm_bitwriter.cma -pp camlp4oof minml.ml -o minml

how do I get CLSQL to look for mysql.h in non-standard directory?

in the error log:
CLSQL is doing:
gcc -I /usr/local/include/mysql -I /usr/include/mysql -I /sw/include/mysql -I /opt/local/include/mysql -I /usr/local/mysql/include -fPIC -c clsql_mysql.c -o clsql_mysql.o
and gets error:
clsql_mysql.c:34:19: mysql.h: No such file or directory
and a bunch of C errors because it doesn't include a header.
I want it to do:
gcc -I /usr/local/include/mysql -I /usr/include/mysql -I /sw/include/mysql -I /opt/local/include/mysql -I /usr/local/mysql/include <b>-I /usr/local/mysql/include/mysql</b> -fPIC -c clsql_mysql.c -o clsql_mysql.o
I tried running: (clsql:push-library-path #P"/usr/local/mysql/include/mysql/") already. Didn't work.
HALP!
check that file exists and no permissions problem by inserting #include with full name at the beginning of clsql_mysql.c file:
#include "/usr/local/mysql/include/mysql/mysql.h"
if compiles well - undo changes and resolve path provided by -I parameter
if doesn't compile and says "file does'nt exist" - check that file exists and no permission problems
I'm not familiar with CLSQL specifically, but if it uses cffi-grovel to generate that command, then prior to loading it you should try adding your "-I/usr/local/mysql/include/mysql/" to the cffi-grovel::*cc-flags* list. You could also add it in the asd file, as the grovel-file asdf component takes an optional cc-flags argument.