GCC Flag to SCONS - c++

I`m building a library using make with the following flags:
INCL = `PKG_CONFIG_PATH=/mingw64/lib64/pkgconfig:/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig:/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig pkg-config --cflags ipopt` $(ADDINCFLAGS)
LIBS =
'PKG_CONFIG_PATH=/mingw64/lib64/pkgconfig:/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig:/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig pkg-config --libs ipopt'
How can I translate this to build with SCONS ?
My issue is to understand how the path definition PKG_CONFIG_PATH= ... is passed to SCONS.

Likely you'll want to use either ParseFlags() or MergeFlags()
See:
http://scons.org/doc/production/HTML/scons-man.html
Further there's a reasonable example in the SCons wiki here:
https://bitbucket.org/scons/scons/wiki/UsingPkgConfig

Related

Can not compile mlpack C++ program on Ubuntu

i downloaded mlpack and its dependencies from ubuntu repos as described in the docs using :
sudo apt-get install libmlpack-dev libmlpack-bin and then i ran :
pkg-config --cflags mlpack
And pkg-config --libs mlpack
And pkg-config --modversion mlpack
to make sure everything works and i got the expected outputs. Now in codeblocks i put the mlpack library directory in the search directory and the pkg-config --cflags mlpack in the compiler options, and the pkg-config --libs mlpack in the linker options. But when i build it gives me ld errors: libraries were not found. What frustrates me is that i have done the exact same procedure with other C++ libraries like OpenCV and it worked. So any help ? Does anyone managed to get it work before on linux ?
------Update------
I managed to fix it by only adding -lmlpack and -larmadillo to the linker options and not adding all --libs.

Link PCL libraries while compiling C++ programs in Linux

I am new to the Point Cloud Library. There is a thing that has been bugging me for some time.
So, on my system, whenever I have to compile a C++ program, which requires OpenCV libraries to be linked, I use the following terminal command:
g++ -std=c++11 fileName.cpp -o executableFile `pkg-config --cflags --libs opencv`
Now, things have turned to a point where I have to use PCL. But, everywhere (including the PCL's official website) people link PCL libraries using a CMake file, and I am not familiar with CMake.
Is there a way to include the PCL libraries without writing a CMake file and just including some more flags/parameters to the terminal command?
I am using Ubuntu 18.04.
I experimented for a while, and here is how I figured this out.
man pkg-config tells you the folders where pkg-config looks for .pc files. So, I checked those folders for the exact .pc file names that I want pkg-config to link with my .cpp file. I found the required file (pcl_io-1.11.pc) at \usr\local\lib\pkgconfig
Next, I modified my terminal command to the following (please consider two back-quotes as a single back-quote below)
g++ -std=c++14 pcd_write.cpp -o pcd_write ``pkg-config --cflags --libs pcl_io-1.11`` -lboost_system
Note: Not including the -lboost_system would result in another error message. I found this helpful.
This compiled successfully. But, on running the executable, I would get this error message:
./pcd_write:error while loading shared libraries:libpcl_io.so.1.11:cannot open shared object file:No such file or directory
The solution to this problem was found here
sudo /sbin/ldconfig -v
Then, running the executable gave the expected results.

C++ where are the flags for linking libraries documented?

With every new library I want to use I have noticed there is a specific flag, or set of flags, I have to add to the compile in order for it to actually link the library.
For example with GL GLEW and GLUT I use "-lglut -lGLU -lGL".
The problem is the only way to find these flags that I need is to search endlessly on google for them. Is there a 'standard' place to find these flags for any library? Are they appended to the tops of the headers or something? I hope it's just something obvious I'm missing.
Typically, you develop an intuition for discovering these things on the platforms you develop for. It does suck.
For example, on my Debian development system, I would start by checking pkg-config for the library I want.
pkg-config --list-all | less -i
It looks like there's a package named gl. So, you can get the linker flags using pkg-config:
pkg-config --libs gl
pkg-config --cflags gl
Then you can put that into your Makefile:
gl_cflags := $(shell pkg-config --cflags gl)
gl_libs := $(shell pkg-config --libs gl)
override CFLAGS += $(gl_cflags)
override LIBS += $(gl_libs)
my_app: my_app.o
$(CC) $(LDFLAGS) -o $# $^ (LIBS)
This doesn't work for all libraries, only those with .pc files installed. For example, it won't work for LibJPEG. In these cases, you would either remember the flags (-ljpeg) or you would use an Autoconf / CMake / etc. configuration script to discover the flags at configuration time.
And, none of this will work at all if you don't have the development versions of your libraries installed.
sudo apt-get install libgl1-mesa-dev
P.S. GLU is a bit obsolete.
I'll assume you are asking about GCC/G++ compiler.
The flag is -l<libName>, where <libName> is the name of the library you want to link against. For example, -lGL links against the GL library.
The reason some libraries require multiple flags in certain order is simply the way they depend on each other (the libraries your library depends on might also depend on some other ones, and so on). The library's documentation should solve the problem in most cases.

Linking the Allegro library to a C++ application using the g++ compiler (Ubuntu)

In trying to get Allegro (A C++ game programming library) to work with a very simple C++ application in Ubuntu 12.04, I am unable to get the program to compile with the allegro header definitions. It returns the error allegro.h - no such file or directory found. I tried running a pkg-config to find the proper linker command, but that didn't help in compilation.
I am almost certain it is installed correctly at this point. I tried using a pkg-config --cflags --libs allegro-5.0 for the include file paths, none of which worked when using in the g++ compile line.
Thanks in advance.
Running a pkg-config --cflags --libs allegro-5.0 told me wrong on the include path. It told me to use -I/usr/local/include and after some digging into that folder, I found that the include path is -I/usr/local/include/allegro5 instead. It is compiling fine now.

Backslash on Include directories with pkg-config on Mac OS Lion

Good evening everybody,
I have virtually no experience with pkg-config but it seems that I will have to use it in working with openssl. Im on a Mac, which might be of some importance.
The problem is:
i compile my testing program with
cc test.cc `pkg-config --libs --cflags openssl` -o test
i have compiled openssl and installed it in ~/openssl afterwards adding ~/openssl/lib/pkgconfig to the PKG_CONFIG_PATH
since I want to use the newest version instead of the preinstalled one, I specify the options with every compilation
the result of running pkg-config --libs or pkg-config --cflags openssl is -L\~/openssl/lib -lssl -lcrypto
This begs the question for me why there is a backsash and whether my compiled version is used or the preinstalled one and if the first one is the case how i could possibly fix this...
Any kind of help is appreciated
The expansion of ~ to your home directory only occurs in certain circumstances. Basically, it's the shell that's doing it. If a program or a file API sees the tilde, it is interpreted as a literal; it's not expanded.
Use $HOME when setting PKG_CONFIG_PATH instead, as in $HOME/openssl.