Hi I am using gtkmm in an XCode project and I am wondering how I can include the headers without using the command line and adding them in manually. Is there a way to using pkgconfig in XCode without doing it this way, ie some extra params or something?
Any help would be appreciated.
May be look here
You can use pkg-config, if a .pc file for that package is present. These files are generally located at /usr/share/pkgconfig. You can prepare your own .pc file also by writing the header files directory and library directory in a specified format.
Just have a look at the contents of a .pc file and it it intuitive to understand.
I know that this is old, but I was able to get gtkmm working in Xcode 6 so I figured I'd share.
Assuming that gtkmm and Xcode 6 has been installed on your mac, the following steps should allow you to add gtkmm to an existing Xcode (c++) project.
Run pkg-config <pkgconfig file name> —cflags —libs in the terminal. This command returns the linker flags/compiler flags Xcode will need. I have gtkmm 2.24.2_1 installed on my machine so for me the command is pkg-config gtkmm-2.4 —cflags —libs for me. I cannot guarantee that this works for other versions.
To determine the name of your .pc file, mine was located inside /usr/local/Cellar/gtkmm/2.24.4_1/lib/pkgconfig
The terminal command should return all the required flags, here's what mine returns:
-D_REENTRANT -I/usr/local/Cellar/gtkmm/2.24.4_1/include/gtkmm-2.4 -I/usr/local/Cellar/gtkmm/2.24.4_1/lib/gtkmm-2.4/include -I/usr/local/Cellar/atkmm/2.22.7/include/atkmm-1.6 -I/usr/local/Cellar/gtk+/2.24.28_2/include/gtk-unix-print-2.0 -I/usr/local/Cellar/gtk+/2.24.28_2/include/gtk-2.0 -I/usr/local/Cellar/gtkmm/2.24.4_1/include/gdkmm-2.4 -I/usr/local/Cellar/gtkmm/2.24.4_1/lib/gdkmm-2.4/include -I/usr/local/Cellar/glibmm/2.44.0/include/giomm-2.4 -I/usr/local/Cellar/glibmm/2.44.0/lib/giomm-2.4/include -I/usr/local/Cellar/pangomm/2.36.0/include/pangomm-1.4 -I/usr/local/Cellar/pangomm/2.36.0/lib/pangomm-1.4/include -I/usr/local/Cellar/glibmm/2.44.0/include/glibmm-2.4 -I/usr/local/Cellar/glibmm/2.44.0/lib/glibmm-2.4/include -I/usr/local/Cellar/cairomm/1.11.2_1/include/cairomm-1.0 -I/usr/local/Cellar/cairomm/1.11.2_1/lib/cairomm-1.0/include -I/usr/local/Cellar/libsigc++/2.4.1/include/sigc++-2.0 -I/usr/local/Cellar/libsigc++/2.4.1/lib/sigc++-2.0/include -I/usr/local/Cellar/gtk+/2.24.28_2/include/gtk-2.0 -I/usr/local/Cellar/gtk+/2.24.28_2/lib/gtk-2.0/include -I/usr/local/Cellar/pango/1.36.8_1/include/pango-1.0 -I/usr/local/Cellar/atk/2.16.0/include/atk-1.0 -I/usr/local/Cellar/cairo/1.14.2_1/include/cairo -I/usr/local/Cellar/pixman/0.32.6/include/pixman-1 -I/usr/local/Cellar/fontconfig/2.11.1/include -I/usr/local/Cellar/freetype/2.5.3_1/include/freetype2 -I/usr/local/Cellar/freetype/2.6_1/include/freetype2 -I/usr/local/Cellar/libpng/1.6.17/include/libpng16 -I/usr/local/Cellar/gdk-pixbuf/2.30.8/include/gdk-pixbuf-2.0 -I/usr/local/Cellar/libpng/1.6.17/include/libpng16 -I/usr/local/Cellar/glib/2.44.1/include/glib-2.0 -I/usr/local/Cellar/glib/2.44.1/lib/glib-2.0/include -I/usr/local/opt/gettext/include -L/usr/local/Cellar/gtkmm/2.24.4_1/lib -L/usr/local/Cellar/atkmm/2.22.7/lib -L/usr/local/Cellar/gtk+/2.24.28_2/lib -L/usr/local/Cellar/gtkmm/2.24.4_1/lib -L/usr/local/Cellar/glibmm/2.44.0/lib -L/usr/local/Cellar/pangomm/2.36.0/lib -L/usr/local/Cellar/glibmm/2.44.0/lib -L/usr/local/Cellar/cairomm/1.11.2_1/lib -L/usr/local/Cellar/libsigc++/2.4.1/lib -L/usr/local/Cellar/gtk+/2.24.28_2/lib -L/usr/local/Cellar/pango/1.36.8_1/lib -L/usr/local/Cellar/atk/2.16.0/lib -L/usr/local/Cellar/cairo/1.14.2_1/lib -L/usr/local/Cellar/gdk-pixbuf/2.30.8/lib -L/usr/local/Cellar/glib/2.44.1/lib -L/usr/local/opt/gettext/lib -lgtkmm-2.4 -latkmm-1.6 -lgtk-quartz-2.0 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgtk-quartz-2.0 -lgdk-quartz-2.0 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl
Now in Xcode open your project file and select your target, within build settings you then need to copy the flags you got from the terminal into “Other Linker Flags” and “Other C Flags”
At this point you should be able to run, compile, build, etc. c++ projects that use gtkmm in Xcode.
Answer based on the details from user2618142's answer + link
Also just as an aside, if you are getting the error
no matching constructor for initialization of 'GTK::Main'
on the line Gtk::Main kit( argc, argv ) it is likely because Xcode by default creates a main like this int main(int argc, const char * argv[]) but gtkmm uses argv as a non const parameter, so you need to change your main function to int main(int argc, char * argv[]).
Related
I'm trying to compile a simple Boost Wave example and while Xcode is recognizing the headers, it is giving me a slew of Apple Mach-O Linker(Id) Errors. I have encountered this before and I don't remember how I solved it. Please help!
I have attached a screenshot.
P.S. I have Boost 1.57.0 and it works just fine with any Xcode Project. For whatever reason, though, it isn't in the case when it involves the header boost/wave.hpp like so...
#include <boost/wave.hpp>
Also, I ruled out the body of the code as a culprit. This throws the linker erros:
#include <boost/wave.hpp>
int main() { return 0; }
Other Boost headers like these, do not:
#include <boost/function.hpp>
int main() { return 0; }
I figured it out, but have no idea why this is the case. If anyone would like to add an explanation, that would be splendid. I had to manually add the various dynamic and static libraries referenced in each of the above issues. I attached a new screenshot so others having this issue can see the end result.
Well, the explanation is very simple. In order to be able to build your project, the compiler working under the hood needs to know:
Where to search for the #include <..> within your project's files: this corresponds to the -I directory option for the g++ compiler. In Xcode this corresponds to set the "Header Search Paths" in the Build Settings of you project.
Without specifying the Header Search Paths, you will get errors on the #include lines since Xcode doesn't know where to look for those included files.
Where to search for the library that must be linked to your source code while building the project: this corresponds to the -L directory option for the g++ compiler. In Xcode this corresponds to set the "Library Search Paths" in the Build Settings of you project.
Without specifying the ** Library Search Paths**, you will get errors while trying to build your project since Xcode doesn't know where to look for the linked libraries.
What libraries must be linked to your project files at compilation time: this corresponds to the -l linking option for the g++ compiler.
In Xcode this corresponds to add the .dylib files to the Link Binary With Libraries in the Build Phases settings of your project. Note that you don't need to add manually the libraries to the main folder of your project, the last described step suffice.
See here and here for the directory and linking options of the g++ compiler, respectively.
I'm trying to build a C++ program, that needs lipqxx functionalities. I'm on Ubuntu and I'm trying to use Kdevelop.
I did it successfully with Code::Blocks, but I'm trying to find a better IDE.
Now, what I've done with Kdevelop.
I created a simple example:
#include <pqxx/pqxx>
int main(int argc, char **argv) {
pqxx::connection c("dbname=xx host=localhost user=xx password=xx");
return 0;
}
I modified the CmakeList.txt to include the pqxx directory and to link with libpqxx.so:
cmake_minimum_required(VERSION 2.6)
project(testkdev)
include_directories ("/usr/include/pqxx")
LINK_DIRECTORIES("/usr/lib")
add_executable(testkdev main.cpp)
TARGET_LINK_LIBRARIES(testkdev libpqxx.so)
install(TARGETS testkdev RUNTIME DESTINATION bin)
At this point, the build process works.
But I need to do something else, I want to work in C++11.
So I add a -std=c++11 option, right clicking on my project, Open Configuration > Cmake > Advanced Values > CMAKE_CXX_FLAGS.
And I get the following errors:
/home/francis/projects/testKDEV/build> make -j2
[100%] Building CXX object CMakeFiles/testkdev.dir/main.cpp.o
In file included from /usr/include/c++/4.9/memory:79:0,
from /usr/include/c++/4.9/tr1/memory:39,
from /usr/include/pqxx/util.hxx:31,
from /usr/include/pqxx/util:18,
from /usr/include/pqxx/except.hxx:27,
from /usr/include/pqxx/except:19,
from /usr/include/pqxx/result.hxx:33,
from /usr/include/pqxx/result:19,
from /usr/include/pqxx/binarystring.hxx:26,
from /usr/include/pqxx/binarystring:18,
from /usr/include/pqxx/pqxx:17,
from /home/francis/projects/testKDEV/main.cpp:2:
/usr/include/c++/4.9/functional:1034:20: error: expected template-name before ‘<’ token
: tuple_element<__i, _Tuple> { };
^
/usr/include/c++/4.9/functional:1034:20: error: expected ‘{’ before ‘<’ token
/usr/include/c++/4.9/functional:1034:20: error: expected unqualified-id before ‘<’ token
/usr/include/c++/4.9/functional:1054:17: error: ‘tuple_size’ was not declared in this scope
(__i < tuple_size<_Tuple>::value)>
^
/usr/include/c++/4.9/functional:1054:35: error: ‘::value’ has not been declared
(__i < tuple_size<_Tuple>::value)>
and it goes on and on with errors...
Could anybody please help me understanding what I'm doing wrong ?
I don't know Kdevelop but I had similar problem. I use Eclipse. There is my question and answer. That is in Polish, so find someone, who can translate that. My English isn't too good but I'm going to transtalte as well as I can.
My question (forum.dobreprogramy.pl)
You need libpqxx-4.0.1. Download these packages:
md5sum
libpqxx-4.0.1
Next:
check package: md5sum -c libpqxx-4.0.1.tar.gz.md5sum
If it's ok: tar -xzvf libpqxx-4.0.1.tar.gz
cd libpqxx-4.0.1
./configure --prefix=/usr/local --enable-shared
You can choose path other than "/usr/local". There will be installed libpqxx.
make clean
make
make install
Now you should have header files in /usr/local/include and libpqxx.a, libpqxx.so in /usr/local/lib. If everything is ok, link libraries in IDE. I don't know, how to do this in your IDE but this is generally the same but properties are in different places. For example in Eclipse CDT:
In Project/properties/C\C++ Buid/Settings/GCC C++ Compiler/Includes/include paths type: /usr/local/include
In GCC C++ Linker/Libraries/Library search path type: /usr/local/lib
In GCC C++ Linker/Libraries/Libraries type: pqxx
In project: #include
Now try to compile. If it's ok, try to run program. If you have problem like in post #15
error while loading shared libraries: libpqxx-4.0.so: cannot open shared object file: No such file or directory
Go to /etc/ld.so.conf.d/ and make there new file named libpqxx-4.0.1.conf next open the file nad type there /usr/local/lib
After that issue the command ldconfig
In my case it was everything to connect with PostgreSQL using libpqxx and C++11. Good luck.
Up until now I've managed to get Xcode to link to the Gnu Scientific Libraries (GSL) which I've installed under /usr/local/lib/ and with header files under /usr/local/include. Under "Build Phases" > "Link Binary With Libraries" I had added libgsl.a etc. Today, Xcode gives an error message claiming it can't find header files.
For example
#include <stdio.h>
#include <gsl/gsl_matrix.h>
int main(int argc, const char * argv[])
{
printf("Hello, World!\n");
return 0;
}
results in 'gsl/gsl_matrix.h' file not found. I've tried to change the User Header Search path to no avail. Using gcc main.c -lgsl -lgslcblas on the command line works perfectly. Could anyone tell me what exactly one needs to do to get this to work in Xcode? Also, why has it suddenly stopped working for no apparent reason.
Many kind thanks.
I had same problem when I upgraded to 4.3.3 with include files installed in my /usr/local/include folder. After some head banging, I discovered that I had to add /usr/local/include to the "Header Search Paths" setting under Search Paths in Project Build Settings. I did NOT have to do that in the previous version of XCode. Don't know why it changed, but hope this works for you.
In Xcode 12.x make sure you select the tab All (instead of the preselected basic):
Thanks for help.
In Xcode 4.6 I have to:
Change default compiler to: LLVM GCC 4.2
And add this paths:
Framework Search Paths: /Library/Frameworks
Header Search Paths: /usr/local/include
Library Search Paths: /usr/include/lib
For a week I've been struggling with compiling openCV programs. I've tried everything I could possibly find on the internet.
What I did is: I've downloaded OpenCV-2.3.1-win-superpack.exe and followed this official installation guide.
In the CMake (gui) my source was: D:\opencv and build destination was: C:\opencv.
I've also added C:\opencv\install\bin;C:\opencv\bin to my system's PATH variable.
What I want is to compile openCV programs on my Windows OS using MinGW's gcc/g++ compilers.
I've tried various gcc/g++ parameters that I've found on the internet and days playing with the -I and -L options the compiler can never find the openCV functions or structures.
What I am trying to compile:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
Error:
Input:
gcc test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccK4MfHv.o:test.c:(.text+0xa0b): undefined reference to `cvFree_'
Or with g++:
Input:
g++ test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccXCTKa1.o:test.c:(.text+0x1e): undefined reference to `cvNamedWindow'
Side note: trying to compile in VS2005 I get the same error.
Thank you for your time!
In case someone else needs to solve this issue, here's how I got the posted OpenCV/HighGUI sample code to compile in Windows 7 x64 using MinGW, MSYS, and CMake:
build OpenCV from source using MinGW/MSYS/CMake. This is because I could not get the MinGW compiled version in the OpenCV-win-SuperPack to link properly in MinGW/MSYS/Windows 7 x64.
For full reference, here's how I compiled OpenCV:
make sure you have an up-to-date CMake (v2.6 or later) and MinGW (with GCC, G++, and MSYS options) installed
if you want the new Qt-based OpenCV HighGUI front-end, you will need to install Qt 4 (SDK).
download a OpenCV source/superpack version 2.2 or later (I used OpenCV-2.3.1-win-superpack.exe)
unzip the contents to [OPENCV_SOURCE_DIR] (I put it in C:/opencv, so there should be a file at C:/opencv/README for example)
create a [OPENCV_BUILD_DIR] directory elsewhere (I used C:/opencv/build/mingw)
use the CMake-GUI tool, specify the source directory as [OPENCV_SOURCE_DIR], the build directory as [OPENCV_BUILD_DIR], and click "Configure".
you may wish/need to go tweak the options (e.g. I ticked "Qt" and "Qt-OpenGL" entries, then clicked "Configure" again, then had to provide the path to the qmake executable)
once you have finished configuring OpenCV, click "Generate"
in a MSYS terminal, browse to [OPENCV_BUILD_DIR], and run "make" to build the code (this may take a while)
once the has been built properly, run "make install", which collects the built code/libraries/include dirs into [OPENCV_BUILD_DIR]/install folder (or a different folder if you changed the corresponding option when using the CMake-GUI tool)
add [OPENCV_BUILD_DIR]/install/bin folder to the PATH environmental variable. If you do not know how to do this, then I'd recommend using the Path Editor GUI tool.
if you end up using Qt, you will also need to put the bin folder of Qt SDK in the PATH environmental variable. This is the folder that includes qmake.exe.
put the following sample code into a file called test.c. I modified the includes slightly to make them compatible with OpenCV v2.2 and above.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
in a MSYS terminal, browse to the folder where you put test.c, and run:
gcc -o test -I"[OPENCV_BUILD_DIR]/install/include" test.c \
-L"[OPENCV_BUILD_DIR]/install/lib" \
-lopencv_core[OPENCV_VERSION] \
-lopencv_imgproc[OPENCV_VERSION] \
-lopencv_highgui[OPENCV_VERSION]
So in my case:
gcc -o test -I"/c/opencv/build/mingw/install/include" test.c \
-L"/c/opencv/build/mingw/install/lib" \
-lopencv_core231
-lopencv_imgproc231
-lopencv_highgui231
Path Editor: http://www.redfernplace.com/software-projects/patheditor/
You have the directory, C:\opencv\install\bin, to locate libraries on the gcc/g++ command line, but I think you'll also need to specify the libraries to use as linker inputs as well. I'm not sure what libraries are part of the OpenCV distribution, but going by the example on the instruction page you linked to, one might be:
-lopencv_calib3d220.dll
You'll probably have to add one or more other ones (that follow the name pattern lib*.a in the C:\opencv\install\bin directory - or maybe some other lib directory that you should be passing in a -L option).
This is my first question here, so sorry in forward if it is not well formulated or stupid.
I am trying to use the octave libraries with C++
I am using Qt creator on Ubuntu (linux noob)
#include "octave/oct.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Matrix matrix(3,4);
return a.exec();
}
At first I got some undefined references errors. I figured out the program is missing libraries, so I looked for the library "liboctave.so". I found it in usr/lib/octave-3.2.4. To be more precise there was a symbolic link named "liboctave.so" pointing to "liboctave.so.3.2.4" file. I used the QtCreators "add Library" feature to add the library to my project. The program generated this code in my .pro file
unix:!macx:!symbian: LIBS += -L$$PWD/../../../../usr/lib/octave-3.2.4/ -loctave
INCLUDEPATH += $$PWD/../../../../usr/lib/octave-3.2.4
DEPENDPATH += $$PWD/../../../../usr/lib/octave-3.2.4
The program built without error. Not even complaining about undefined references. But when I run it I get
Starting /home/martin/Projects/test-build-desktop/test...
/home/martin/Projects/test-build-desktop/test: error while loading shared libraries: liboctave.so: cannot open shared object file: No such file or directory
/home/martin/Projects/test-build-desktop/test exited with code 127
I cannot figure out why it cannot find the file. I am looking at the file with my bare eyes.
I figured out that the problem may be permission, so I copied the "liboctave.so.3.2.4" file to the project location, renamed it "liboctave.so" and added all permissions for everybody. Then added this library using the Qtcreator "add library" feature and I still get the same error.
Please help me
The liboctave is not installed in standard location, when you compile it your povide
a parameter -L$$PWD/../../../../usr/lib/octave-3.2.4/ however in the run
time it is not known.
So you have two options:
Provide environment variable LD_LIBRARY_PATH=/full/path/to/usr/lib/octave-3.2.4 and then run the program:
export LD_LIBRARY_PATH=/full/path/to/usr/lib/octave-3.2.4
Hardcode the path withing excutable using an additional option: -Wl,-rpath=$$PWD/../../../../usr/lib/octave-3.2.4/
And it would search for it in this location.