Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Linker issues and pkg-config
Linker issues and pkg-config [message #1715432] Mon, 23 November 2015 14:26 Go to next message
Joe C. is currently offline Joe C.Friend
Messages: 5
Registered: November 2015
Junior Member
I have a really simple program (single .c file, it just open an input and output port and passes audio, that's all) that uses the Jack Audio Connection Kit but I can't figure out how to get it to compile under Eclipse. It's got to be a linker issue. I've Googled and I've searched the help. It appears that there used to be a feature that directly dealt with pkg-config but for whatever reason, it no longer exists. To compile this on the command line is pretty simple...
gcc `pkg-config --cflags --libs jack` -o simple simple_client.c


That compiles no problem (no warnings or errors). When I attempt to compile with Eclipse I get this...

Here's the output I get:
09:18:33 **** Incremental Build of configuration Debug for project SimpleJackClient ****
make all
Building file: ../simple_client.c
Invoking: GCC C Compiler
gcc -O0 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"simple_client.d" -MT"simple_client.o" -o "simple_client.o" "../simple_client.c"
Finished building: ../simple_client.c

Building target: libSimpleJackClient
Invoking: GCC C Linker
gcc -shared -o "libSimpleJackClient" ./simple_client.o
/usr/bin/ld: ./simple_client.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
./simple_client.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
makefile:29: recipe for target 'libSimpleJackClient' failed
make: *** [libSimpleJackClient] Error 1


No matter what I do, it always fails. I've tried to enter the `pkg-config --cflags --libs jack` line in various places, as well as what the output of that is ( which is -ljack ) in various places, but I'm not getting anywhere. Can anyone point me in the right direction?

Cheers, Joe
Re: Linker issues and pkg-config [message #1715481 is a reply to message #1715432] Tue, 24 November 2015 01:38 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
The message with -fPIC is a clue.

These may help:
https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options (look for -fPIC)
http://stackoverflow.com/questions/332767/recompile-with-fpic-option-but-the-option-is-already-in-the-makefile

But this is for generating a library and your command line seems to want to build an executable.
So why use the -shared option? It's for producing a shared library.
https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#Link-Options (look for -shared)

You need to use at least `pkg-config --libs jack` on the link line. It sets the lib options needed for libjack.

You need to use at least `pkg-config --cflags jack` on the compile line to get the cflags needed for using libjack.

It's OK to combine --cflags and --libs as gcc will use just what it needs.

When using Eclipse, you have to modify the the tool chain commands found in
Project ==> Properties ==> C/C++ Build ==> Settings

A problem arises if Eclipse doesn't start the commands in a shell. If this is the case (and I think it is) then the back quotes will be passed to gcc which has no idea what to do with them.

I't probably best to make two build variables (say, JACKCFLAGS and JACKLFLAGS) in Project ==> Properties ==> C/C++ Build ==>Build Variables using the Add... button and paste the output of pkg-config --cflags jack and pkg-config --libs jack respectively as the values.

You then would modify the tool chain settings to use ${JACKCFLAGS} in the compiler command and ${JACKLFLAGS} in the linker command

[Updated on: Tue, 24 November 2015 02:00]

Report message to a moderator

Re: Linker issues and pkg-config [message #1715492 is a reply to message #1715481] Tue, 24 November 2015 04:11 Go to previous message
Joe C. is currently offline Joe C.Friend
Messages: 5
Registered: November 2015
Junior Member
Thanks for the time put into that response, David! Much appreciated! Smile

Quote:
So why use the -shared option? It's for producing a shared library.


That was a big clue, the "shared" option was checked by default (and I didn't even think to look there). After unchecking that, the -fPIC error went away, and creating JACKLFLAGS with a value of -ljack solved the other problems (there was no output from --cflags).

Cheers, Joe

[Updated on: Tue, 24 November 2015 04:12]

Report message to a moderator

Previous Topic:Error During Clean of the Debug Build Project
Next Topic:Console debuging
Goto Forum:
  


Current Time: Thu Apr 25 11:27:17 GMT 2024

Powered by FUDForum. Page generated in 0.03588 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top