I've tried to use libqmi but I can't get through the linker. It keeps saying "undefined reference" on libqmi functions. Any suggestions what is needed?
Paths and libraries are available for gcc, the symbols are inside libqmi-glib, looks like everything is in place.
The code is the simplest possible, I think.
int main(int argc, char **argv)
{
GFile *qmi = g_file_new_for_path("/dev/cdc-wdm0");
printf("%li\r\n", (long int)(qmi));
g_object_unref(qmi);
return 0;
}
And the build goes like this:
gcc -I/usr/local/include/libqmi-glib/ -I/usr/include/glib-2.0/ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ whatever.c -L/usr/local/lib/ -L/usr/lib/x86_64-linux-gnu/ -lqmi-glib -lglib-2.0
You're missing the link to libgobject-2 and libgio-2.
Anyway, the best way to compile a program using libqmi is to use pkg-config as that knows all the cflags and ldflags you should be using; e.g. you could probably do this, assuming you installed libqmi in /usr/local:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig gcc $(pkg-config --cflags qmi-glib) whatever.c $(pkg-config --libs qmi-glib)
Related
For reference: i am currently on Manjaro (Arch Linux) and am using the GNU g++ compiler. I want to create a program for JACK (Jack Audio Connection Kit) and am now trying to use their API provided here. I have Jack2 installed, but also tried it with Jack2-dbus. I found something in the AUR called jackcpp, but that didn't help neither.
To get to my problem: I fail to compile their example clients listed, and obviously I fail to build my own using that API. I suspect it is broken, but I can't imagine noone reporting it so I don't really know what to do now.
In my jacktest.cpp the following is written:
#include <iostream>
#include "jack/control.h"
int main(){
jackctl_server_t *server;
jackctl_driver_t *driver;
if (jackctl_server_start(server, driver)) {
std::cout << "Started!";
return 0;
}else{
std::cout <<"Failed!";
return 1;
};
}
based on the function documented here. Try to start a jack server and return a bool if operation successful or not.
If I try to compile this (with 'pkg-config' as I am supposed to):
$ g++ -o jacktest `pkg-config --cflags --libs jack` jacktest.cpp
it throws:
jacktest.cpp:8:44: error: too many arguments to function 'bool jackctl_server_start(jackctl_server_t*)'
if (jackctl_server_start(server, driver))
So I checked and indeed, in my /usr/include/jack/control.h, it defines jackctl_server_start with only one argument. I don't know if their documentation is outdated or if I am missing files/have the wrong ones...
Then I tried to do it with only one argument
...
if (jackctl_server_start(server)) {
...
which then throws:
/usr/bin/ld: /tmp/ccxm3fWC.o: undefined reference to symbol '_ZNSt8ios_base4InitD1Ev##GLIBCXX_3.4'
/usr/lib/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I tried to rearrange the arguments:
$ g++ -o jacktest `pkg-config --cflags --libs jack` jacktest.cpp
$ g++ -o jacktest jacktest.cpp `pkg-config --cflags --libs jack`
$ g++ jacktest.cpp `pkg-config --cflags --libs jack` -o jacktest
$ g++ jacktest.cpp -o jacktest `pkg-config --cflags --libs jack`
which always throws the same error...
now the thing that really makes me think something is broken: another jacktest_2.cpp now including jack.h and excluding control.h
#include <iostream>
#include "jack/jack.h"
int main(){
jack_client_t *client;
if (client = jack_client_new("test_client")) {
std::cout << "Running!";
return 0;
}else{
std::cout <<"Not Running!";
return 1;
};
}
which I CAN compile:
$ g++ -o jacktest_2 jacktest_2.cpp `pkg-config --cflags --libs jack`
altough it gives me complains that this function is depricated, the program does what it should too! So at least some of it is working?!
Also:
$ g++ -print-file-name=jack
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../lib/jack
is that normal? There is no lib/jack in usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1
To conclude: I really NEED control.h, I even went as far as changing control.h and include their 'driver' part from the API Docs back into the function, but that didn't get me anywhere neither... (undefined reference...) I feel like I am missing something really simple, or something really is broken with that API. I have been on this for almost a week, and I just can't figure it out.
If anyone stumbles upon this and wondered what happend: I posted this in the JackAudio forum here. Anyone can read it if he/she wants to, but I will mark this question as answered now, since it really is not a C++ or compiling problem but rather a Jack problem. Thank you!
I tried to build this, but always got link-time error.
#include <libavutil/log.h>
int main(int argc, char *argv[])
{
::av_log_set_flags(AV_LOG_SKIP_REPEATED);
return 0;
}
My distro is Debian GNU/Linux 8 (jessie). The FFmpeg was built by myself, and the configure command was...
$ ./configure --prefix=/usr/local --disable-static --enable-shared \
> --extra-ldflags='-Wl,-rpath=/usr/local/lib'
The link-error is as follows.
$ g++ foo.cpp -D__STDC_CONSTANT_MACROS -Wall \
> -Wl,-rpath=/usr/local/lib \
> $(pkg-config --cflags --libs libavutil)
/tmp/ccKzgEFb.o: In function `main':
foo.cpp:(.text+0x17): undefined reference to `av_log_set_flags(int)'
collect2: error: ld returned 1 exit status
where the output of pkg-config is...
$ pkg-config --cflags --libs libavutil
-I/usr/local/include -L/usr/local/lib -lavutil
The objdump shows that the shared object libavutil.so does have av_log_set_flogs inside.
$ objdump --dynamic-syms /usr/local/lib/libavutil.so | grep 'av_log_set_flags'
000260f0 g DF .text 0000000a LIBAVUTIL_54 av_log_set_flags
Please note that the g++ command used to build the above application had a linker option -Wl,-rpath=/usr/local/lib, though it still doesn't work. Also, I've tried to monitor with inotifywait if the other version provided by the distro were called. They were not, and the one being opened during execution of g++ was /usr/local/lib/libavutil.so.
Summary:
/usr/local/lib/libavutil.so does have the symbol.
-rpath was used to force to link against the shared library.
Why link-time error? T_T
Any suggestion or information would be highly appreciated! Thanks!
REEDIT: ffplay works fine and ldd shows it use /usr/local/lib/libavutil.so. So, the libraries seems not broken, and the problem becomes how to build my own codes to use the libraries.
This had me baffled too for a while. I managed to google this: http://soledadpenades.com/2009/11/24/linking-with-ffmpegs-libav/
It turns out FFMPEG don't make their header files C++ aware.
Here is the fix:
extern "C"
{
#include <libavutil/log.h>
}
int main(int argc, char *argv[])
{
::av_log_set_flags(AV_LOG_SKIP_REPEATED);
return 0;
}
You need to wrap all ffmpeg header includes with extern "C" linkage.
I'm running Ubuntu. I followed each and every step in the http://wiki.allegro.cc for installation and set up of Allegro5. If I run my program from the command line, I know I need to use
gcc -Wall main.cpp `pkg-config --cflags --libs allegro-5.0
plus any other packges I use. (I don't know what all of it means, but I know I need it)
What I need help with if figuring out what I need to do in Codeblocks > Settings > Compiler so that it will link to the allegro library so that I don't get a hundred and one undefined reference errors. I don't know what I'm looking for, and I don't know where to look. Help a new guy out.
Thanks.
edit: I know I'd need
allegro-config --libs --static
in the Linker for Allegro 4.2
Where can I look and what do I need for Allegro5?
If Codeblocks doesn't support entering `pkg-config --cflags --libs allegro-5.0` directly, then just open up a terminal and type in (no backticks):
pkg-config --cflags --libs allegro-5.0
Then copy/paste the result of that into the compiler settings inside Codeblocks.
I am currently trying to develop a C++ application which will envolve solving some algebraic tasks (such as differentiation or integration) using GiNaC; I've installed it first from the Ubuntu Software Center (Ubuntu 13.04) and afterwards directly from the ftp ftp://ftpthep.physik.uni-mainz.de/pub/GiNaC/ ; however, everytime i try to compile the following example program:
#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main()
{
symbol x("x"), y("y");
ex poly;
for (int i=0; i<3; ++i)
poly += factorial(i+16)*pow(x,i)*pow(y,2-i);
cout << poly << endl;
return 0;
}
i get a list of errors, all starting with "undefined reference to GiNaC::". I have verified that cln is also installed and the header files are on the default locations. Also, when compiling I've used the command g++ -o simple pkg-config --cflags --libs ginac simple.cpp
and g++ -o simple -lginac -lcln simple.cpp, both have failed to compile.
The problem is the order of the parameters on the compile line. Try one of the following two variants:
g++ -o simple simple.cpp `pkg-config --cflags --libs ginac`
g++ -o simple -Wl,--no-as-needed `pkg-config --cflags --libs ginac` simple.cpp
The idea is that the order of the object files and libraries is important to the linker. Very simply put, by default it only links a library if it needs it to resolve some previously unresolved symbols.
The first variant above moves the libraries at the end of the build parameters (so after the object file for your code), while the second variant disables this behavior in the linker.
I ran into the same exact issue, and I found 2 things that does bring you to where you want to be:
I placed -lcln after -lginac on the command line
This enabled me to compile it, but the program would not run. I found the solution to this. The error was "GLIB_CXX_3.4.21 not defined in libstdc++.so.6 with link time reference"
Link statically to libstdc++ with -static-libstdc++
As in:
g++ -g testgin.cpp -o simple -lcln -lginac -static-libstdc++
Peace
How do I reliably figure out link flags for libraries? I always end up googling/digging manuals.
Is there a way to list libraries available for linking, with names and/or descriptions?
edit: Linux system, GNU build chain, classics.
On most Linux systems, you can use pkg-config to list out the compiler options for a given library. For example:
g++ example.cpp $(pkg-config --cflags --libs libpng)
becomes
g++ example.cpp -I/usr/include/libpng12 -lpng12
Or an example with slightly more complicated output:
$ pkg-config --cflags --libs gthread
-D_REENTRANT -I/usr/include/glib-1.2 -I/usr/lib64/glib/include -lgthread -lpthread -lglib