eclipse cdt: add include path from pkg-config - c++

i want to add a dynamic configuration path (generated from pkg-config) to my project. (this is basically for third-party dependencies like boost, so workspace includes is not appropiate, and filesystem include neither because that would be hardcoded and every developer would have to change that manually)
i am on project properties->c++ general->paths and symbols->includes tab->add...->add directory path->variables but i can only select among existing variables, how do i create a new variable dynamically generated from a command line program? like pkg-config --cflags boost-1.43?
this is easy to do in netbeans; you just add the pkg-config commandline with the backquotes in the build additional options and it resolves the build include and even in theory it should update the indexer (although truth be said, last time the indexer was correctly updating from pkg-config was on netbeans 6.8, it has been broken on 6.9 and 6.9.1)
i read this StackOverflow post but i still not sure how it helps this specific case
i read somewhere that you can use $(shell pkg-config...) to generate environment variables but not sure where to place the command
if there is no easy out of the box solution i'll try the script in this blog post
btw, i'm using eclipse helios -cdt 7
thanks!

Pkg-config support is finally coming to CDT and will be finished on August.
http://code.google.com/p/pkg-config-support-for-eclipse-cdt/

you can use $(shell pkg-config --cflags your_libs) in:
Project properties->C/C++ Build->Settings->"Tools Settings" tab->**C Compiler**->Miscellaneous->Other Flags
and
you can use
$(shell pkg-config **--libs** your_libs)
in
Project properties->C/C++ Build->Settings->"Tools Settings" tab->**C Linker**->Miscellaneous->Other Flags
if the linker doesn't link, make sure (for example in the build console window) that the pkg-config flags appear after the objects to link.
you can do this in properties->C/C++ Build->Settings->"Tools Settings" tab->C Linker->Command line pattern moving ${FLAGS} to the end :
from this (for example) :
${COMMAND} **${FLAGS}** ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} **${INPUTS}**
to this :
${COMMAND} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} **${INPUTS} ${FLAGS}**

In eclipse 4.3.2 at least, it looks as though it's possible to simply add
`pkg-config --libs <mylibname>`
in
Project->Properties->C/C++ Build->Settings->GCC {C|C++} Linker->Miscellaneous->Linker Flags
similarly
`pkg-config --cflags <mylibname>`
in
Project->Properties->C/C++ Build->Settings->GCC {C|C++} Compiler->Miscellaneous->Other Flags

what i found so far is that you can do
project-> properties-> c++ build-> build variables
add a new variable of string type.
Call it whatever you like:
UNITTEST_CPP_CXXFLAGS
then set as its value:
$(shell pkg-config --cflags unittest-cpp)
the go to project properties-> c++ general -> path and symbols,
includes.
Select languages c++, otherwise it defaults to assembly source file.
Click add.
On the add directory path, click variables... (because we want to add the variable we have just created)
type the name of the variable (UNITTEST_CPP_CXXFLAGS), press enter and ok
when you rebuild the result of the shell command is replaced in a -I option (for the gnu gcc toolchain at least), in general pkg-config output might include one or more -I so this won't work. Lets go to c++ build->settings->tool settings->gcc c++ compiler->miscellaneous. In there, add ${UNITTEST_CPP_CXXFLAGS} to the other flags.
now the include will be added, but there is no hope of getting the indexer to browse those include!

Use this link at eclipse help/install new spftware. It installs pkg-config. https://raw.githubusercontent.com/TuononenP/pkg-config.p2/master/site.xml
I did find this link in this webpage. https://groups.google.com/forum/#!topic/pkg-config-support-for-eclipse-cdt/HNblZRTKBQQ

Related

How to "override pkg-config" by setting MYLIB_LIBS and MYLIB_CFLAGS?

I'm trying to build some program which uses GNU autotools on a Unix-like OS. It needs some library which my OS distribution doesn't have, say mylib, so I download, build and install that library under /opt/mylib.
Now, I want to tell the configure script to use mylib under /opt/mylib, but it doesn't have a command-line option such as --mylib-location=. However, configure --help tells me:
Some influential environment variables:
... snip ...
MYLIB_CFLAGS C compiler flags for mylib, overriding pkg-config
MYLIB_LIBS linker flags for mylib, overriding pkg-config
... snip ...
I'm guessing these are shell variables I need to set. But - what exactly do I need to set them to?
These variables are expanded in the command-line for compilation and for linking respectively. So, typically, the _CFLAGS would need to indicate an include file search path and _LIBS would need to tell the linker to use the library, plus indicate a search path for it.
In your specific case, and assuming typical layout of /opt/mylibs, you need to set:
MYLIB_CFLAGS=-I/opt/mylib/include
MYLIB_LIBS="-L/opt/mylib/lib -lmylib"
and that should do it. The text about "overriding pkg-config" is due to how pkg-config is used as the default for obtaining these flags. Example (for the PNG library and on my system):
# pkg-config --cflags libpng
-I/usr/include/libpng16
# pkg-config --libs libpng
-lpng16 -lz
pkg-config has search paths configured for include and library directories, plus a repository of .pc files etc., with which it determines the system location of various libraries/packages.

Where is the parameter -Isrc defined in CodeBlocks?

I've got an existing project written in C++ from my predecessor. He used CodeBlocks as an IDE.
I never used this IDE and hardly programmed any C++. He used the tinyxml library, so I added it to the project.
When I try to build it, the build log says something like this:
g++.exe -Wall -fexceptions -DBOOST_THREAD_USE_LIB=1 -D_WIN32_WINNT=0x0501
-Wall -IC:\somepath\boost_1_74_0 -Iinclude -Isrc -IZ:\tinyxml
-c C:\project\AsyncSerial.cpp -o obj\Debug\AsyncSerial.o
Question:
Where is -Isrc -IZ:\tinyxml defined? I don't have any Z:-drive and want to define my own path to the library.
I searched inside the settings and project setup, but didn't find anything like that.
Edit: same goes for:
g++.exe -LC:\somepath\boost_1_74_0\stage\lib -o bin\Debug\project.exe obj\Debug\AsyncSerial.o obj\Debug\main.o obj\Debug\tinyxml\tinystr.o obj\Debug\tinyxml\tinyxml.o obj\Debug\tinyxml\tinyxmlerror.o obj\Debug\tinyxml\tinyxmlparser.o -lws2_32 C:\Programme\boost\boost_1_48_0\stage\lib\libboost_filesystem-mgw46-mt-s-1_48.a C:\Programme\boost\boost_1_48_0\stage\lib\libboost_system-mgw46-mt-s-1_48.a C:\Programme\boost\boost_1_48_0\stage\lib\libboost_date_time-mgw46-mt-sd-1_48.a C:\Programme\boost\boost_1_48_0\stage\lib\libboost_program_options-mgw46-mt-sd-1_48.a C:\Programme\boost\boost_1_48_0\stage\lib\libboost_thread-mgw46-mt-1_48.dll.a C:\Programme\boost\boost_1_48_0\stage\lib\libboost_regex-mgw46-1_48.dll.a
Where does -lws2_32 value come from? I installed boost to the path specified in -L. My boost path was set in global variables and it's the only global variable that is shown.
Edit2:
for information: my path to boost is a relative path in the project folder, and definitely not in program files.
Added pictures of my settings:
Look for the include search directory configuration in
menue "Project"
entry "Build options ..."
tab "Search directories"
subtab "Compiler"
Linker search path nearby in subtab "Linker".
Config of libs to link in tab (not subtab) "Linker settings".
My CodeBlocks is 16.01, but that should not be too different whatever you use.
Quote of OP comment (to make this answer complete):
I found it, they where defined in the Debug/Release Linker settings.
Here "it" refers to the reason/location of the linker paths which did not match the config screenshots in the question.

Using CodeLite IDE for OpenCV in Ubuntu 16.04 LTS

I can compile a sample C++ Code (including OpenCV) using both CMake and following command line:
g++ cv.cpp -o cvapp pkg-config --cflags --libs opencv
But I want to use CodeLite IDE for this purpose. I have added
/usr/include/opencv;/usr/include/opencv2
in the Include Paths under compiler tab in project settings. And added
/usr/local/lib
in Libraries Search Path under Linker tab.
But still, I am getting errors shown in this screenshot for a sample code.
Now is it possible to use CodeLite for OpenCV coding environment? If yes then how?
To use opencv in codelite the simplest option is to continue using pkg-config, you can do this as follows:
Right click on the project name and select settings...
2.Open the following dialog and select the Linker tab, in that window add pkg-config --cflags --libs opencv in linker-options:
Press the apply button and Ok and then compile the project.

C++ Not Finding Installed Library

I am desperately trying to install WebKitGTK+, but I have hit a two-hour impasse.
For one, the tarball provided on the website does not seem to follow any of the typical "build from source" conventions, and there are no instructions anywhere. Any build-from-source instructions they provide involve the unstable repository version, which I do not want to use...and anyhow, those do not seem to work.
I can find both the Webkit (libwebkitgtk-3.0-dev) and Webkit2 (libwebkit2gtk-3.0-dev) versions on the repository (I love Synaptic Package Manager), but though I've installed them, C++ (CodeBlocks) fails on...
#include <webkit/webkit.h>
It is worth noting that one of my employees installed the same package (libwebkitgtk-3.0-dev) successfully from the Debian Wheezy repositories, and he can use them in his code just fine, with the same import statement.
I added the path to /usr/include/webkitgtk-3.0/webkit under Global Compiler Settings --> Search Directories --> Compiler. My employee and I both have the exact same paths to this library added - his work, mine don't.
I'm losing my mind now. Help?
In Codeblocks go to the Project Build Options settings. You can get there by right clicking on the project in the "Projects Management" panel on the left side of the screen and choosing 'Build Options' then clicking on the project itself(NOT just the debug/release options) in the window that shows up. Click the "Search Directories" tab and in the compiler subtab you will need to enter the following path:
/usr/include/webkitgtk-3.0/
When adding them make sure you DO NOT add it as a relative path. Additionally in the "Compiler Settings" -> "Other Options" tab you might need to add one or more of:
`pkg-config --cflags gtk+-3.0 `
`pkg-config --cflags glib-2.0 `
`pkg-config --cflags pango `
`pkg-config --cflags cairo `
`pkg-config --cflags gdk-pixbuf-2.0 `
`pkg-config --cflags atk `
`pkg-config --cflags libsoup-2.4 `
On my system I could not get pkg-config to work for webkitgtk itself.

Installing OpenCV on OSX 10.6 using MacPorts

I tried installing OpenCV following the instructions for a MacPorts install on http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port, typing
sudo port install opencv
in the terminal.
The install/compilation seemed to go fine, and the files are in /opt/local subdirectories as they should be. As a first test, I then tried including highgui.h in a C++ source file:
#include <highgui.h>
but when compiling with g++ or gcc, I get error: highgui.h: No such file or directory. I'm new to developing on a Mac, so maybe I'm missing something?
I thought I might have to set some path variable and after reading some posts I found when googling, I tried setting DYLD_LIBRARY_PATH=/opt/local/lib, but that was wild guess and it didn't seem to help. What should I do to make the compilers find the library?
Thanks!
I couldn't get it to work for quite some time either until I found that there is a pkg-config set.
All you have to do to compile without problems is this:
g++ `pkg-config --libs --cflags opencv` -o helloWorld helloWorld.cpp
or gcc if you are working with C instead of C++.
I hope that helps!
MacPorts installs C/C++ headers in /opt/local/include directory which is not the system default. It means that you have to explicitly tell GCC where to look for headers you are using. You can do that by specifying "-isystem" or "-I" command line options:
-isystem dir
Search dir for header files, after all directories specified
by -I but before the standard system
directories. Mark it as a system
directory, so that it gets the same special treatment as is
applied to the standard system
directories. If dir begins with "=",
then
the "=" will be replaced by the sysroot prefix; see --sysroot and
-isysroot.
-Idir
Add the directory dir to the head of the list of directories to
be searched for header files. This
can be used to override a system
header file, substituting your own version, since these
directories are searched before the
system header file directories.
However,
you should not use this option to add directories that contain
vendor-supplied system header files
(use -isystem for that). If you
use more than one -I option, the directories are scanned in
left-to-right order; the standard
system directories come after.
If a standard system include directory, or a directory
specified with -isystem, is also
specified with -I, the -I option will
be
ignored. The directory will still be searched but as a system
directory at its normal position in
the system include chain. This is
to ensure that GCC's procedure to fix buggy system headers
and the ordering for the include_next
directive are not inadvertently
changed. If you really need to change the search order for
system directories, use the -nostdinc
and/or -isystem options.
I recommend using -isystem because it disables some warnings you cannot fix without modifying the code. For example, using std::auto_ptr if you compile your code with -std=c++0x etcetera.
The same goes for libraries. You have to tell GCC where to find them using -L option.
Referenced from the OpenCV wiki page:
http://opencv.willowgarage.com/wiki/CompileOpenCVUsingMacOSX
Set the environment variables like this:
export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig
export LD_LIBRARY_PATH=/opt/local/lib
and compile opencv code like this:
g++ -bind_at_load `pkg-config --cflags opencv` morphology.c -o morphology `pkg-config --libs opencv`
and then run the code like this:
./morphology
Macports install was working smoothly for me, it is worth to install tbb before installing opencv, massive speedup (and sadly it won't work the other way around).
#include <highgui.h> is not the c++ header.
Use #include<opencv2/highgui/highgui.hpp> and its friends in /opt/local/include and avoid anything in /opt/local/include/opencv.