Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Adding pkg_config as linker option (Linking libraries )
Adding pkg_config as linker option [message #1748511] Wed, 23 November 2016 19:33 Go to next message
Anne Creek is currently offline Anne CreekFriend
Messages: 275
Registered: September 2014
Senior Member
I can add / link library ( OpenCV) ONLY if I prefix the add with colon (Smile
Such as :opencv.so , than the linker outputs -l:opencv.so which is OK.
If I do not use the colon the linker cannot find the library.

Now I am trying to use pkg_config which outputs the packaged libraries WITHOUT the colon, so it does not add anything to the linker options.

Here is a sample of linker output with correctly linked libraries

make all
Building target: TEST_1
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -Xlinker -o "TEST_1" ./src/TEST_1.o -l:libopencv_calib3d.so -l -l:libopencv_highgui.so -l:libopencv_video.so -l:libopencv_imgproc.so -l:libopencv_core.so
g++: error: TEST_1: No such file or directory
makefile:45: recipe for target 'TEST_1' failed
make: *** [TEST_1] Error 1
Re: Adding pkg_config as linker option [message #1748517 is a reply to message #1748511] Wed, 23 November 2016 22:16 Go to previous messageGo to next message
David VavraFriend
Messages: 1417
Registered: October 2012
Senior Member
You can change the "-l:lib" to simply "-l" and drop the ".so"
-l:libopencv_calib3d.so ==> -lopencv_calib3d etc.
OR, you could drop the -l: and simply put libopencv_calib3d.so in the link command
because -lopencv_calib3d is shorthand for libopencv_calib3d.so
You were told this before: https://www.eclipse.org/forums/index.php?t=msg&th=1082479&goto=1747561&#msg_1747561
make all 
Building target: Hello
Invoking: GCC C++ Linker
g++ -L/usr/lib64/openmpi/lib -o "Hello"  ./src/Florp.o ./src/Hello.o ./src/ParmTest.o   -lopencv_calib3d
Finished building target: Hello

ldd Debug/Hello confirms that opencv_calib3d was linked in
$ ldd Debug/Hello
:
	libopencv_calib3d.so.2.4 => /lib64/libopencv_calib3d.so.2.4 (0x00007fccd4163000)
:


What this has to do with pkg-config isn't at all clear.
You seem to be having trouble stating what your posts are about.

FWIW: pkg-config lists the following options for linking opencv
I merely used the first in the above build for an example
$ pkg-config opencv --libs
-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab


Re: Adding pkg_config as linker option [message #1748526 is a reply to message #1748517] Thu, 24 November 2016 01:26 Go to previous messageGo to next message
Anne Creek is currently offline Anne CreekFriend
Messages: 275
Registered: September 2014
Senior Member
I guess I'll give up.
I am not getting thru , so here is summary and my last attempt to explain myself.
.
I know how to add -L and -l options and how they work and do not get why people are telling me that over and over and over.

THE LINKER WON"T LINK "-l" FILE UNLESS IT IS PREFIXED BY ":"
LIKE SO "-l:FILENAME"

GOT THAT ?
Don't know why and frankly don't care at this point.

I WANT to use pkg-config to add the -l libraries , I do not want to add them one by one as I am being told.

That is a function of pkg-config which apparently is foreign concept here.

I have been thru few pkg-config "tutorial "sites, I don't need to be told to check my OS and use Google to find them. I am not an idiot.

I am not sure how to ADD the $(COMMAND) as $(pkg_config...) and that is what everybody is missing.
I have added it as "pre- processing" and as $(COMMAND) in -l option and it did not work.
Please - if you do not understand ALL of this , quit replying or ask for clarification.
Cheers

PS
I have some text from terminal I like to discuss if anybody is still willing to assist me with this but I have given up on using pkg-config for now.















Re: Adding pkg_config as linker option [message #1748560 is a reply to message #1748526] Thu, 24 November 2016 11:54 Go to previous messageGo to next message
David VavraFriend
Messages: 1417
Registered: October 2012
Senior Member
Temper tantrums won't get you too far. You aren't endearing yourself.
Quote:
I know how to add -L and -l options and how they work and do not get why people are telling me that over and over and over.

THE LINKER WON"T LINK "-l" FILE UNLESS IT IS PREFIXED BY ":"
LIKE SO "-l:FILENAME"

Actually, you are quite wrong. I showed you that yet you persist.
You clearly DON"T understand how to use the linker and its options.
The output from pkg-config I gave you in the previous post is EXACTLY what you need to add to the link command.

Quote:
Now I am trying to use pkg_config which outputs the packaged libraries WITHOUT the colon, so it does not add anything to the linker options. Now I am trying to use pkg_config which outputs the packaged libraries WITHOUT the colon, so it does not add anything to the linker options.

You didn't actually ask anything.
If it is a question then it is a vague one.



You can cut and paste the output of pkg-config directly into the link command for the project.
You could also place the same text in a Build Variable then add the variable to the link command.
You could add `pkg-config opencv --libs` to the linker command.
Note those are back quotes which will only work with Linux shell programs.

In the future, ASK a question and BE SPECIFIC if you actually want an answer.
Playing guessing games only wastes time.
Like here: https://www.eclipse.org/forums/index.php?t=msg&th=1082418&goto=1747356&#msg_1747356


Re: Adding pkg_config as linker option [message #1748569 is a reply to message #1748560] Thu, 24 November 2016 14:50 Go to previous messageGo to next message
Anne Creek is currently offline Anne CreekFriend
Messages: 275
Registered: September 2014
Senior Member
You could add `pkg-config opencv --libs` to the linker command.

I guess you do not read my replies.
I already did that and if it work I would not be here, duh

Thanks for your help.
Have a nice day.
Re: Adding pkg_config as linker option [message #1748589 is a reply to message #1748569] Thu, 24 November 2016 20:05 Go to previous message
David VavraFriend
Messages: 1417
Registered: October 2012
Senior Member
Some people just can't be helped I guess.

For the benefit of anyone else stumbling into this thread,
Adding pkg-config with the proper parameters does indeed work.
The following link adds the opencv libraries to the executable.

g++ -L/usr/lib64/openmpi/lib -o "Hello" ./src/Florp.o ./src/Hello.o ./src/ParmTest.o `pkg-config opencv --libs`

Partial listing from ldd. Note the opencv libraries such as opencv_calib3d and opencv_features2d.
$ldd Debug/Hello
	linux-vdso.so.1 (0x00007fff00dfc000)
	libopencv_calib3d.so.2.4 => /lib64/libopencv_calib3d.so.2.4 (0x00007fccd4163000)
	libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fccd3de1000)
	libm.so.6 => /lib64/libm.so.6 (0x00007fccd3ad8000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fccd38c1000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fccd3501000)
	libopencv_features2d.so.2.4 => /lib64/libopencv_features2d.so.2.4 (0x00007fccd325c000)
	libopencv_flann.so.2.4 => /lib64/libopencv_flann.so.2.4 (0x00007fccd2fec000)
:

[Updated on: Thu, 24 November 2016 20:08]

Report message to a moderator

Previous Topic:What is the best/correct way to specify debugger source containers for an external makefile project
Next Topic:how to add a new file type to c/c++->file types
Goto Forum:
  


Current Time: Fri Jan 28 09:51:24 GMT 2022

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

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

Back to the top