LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-20-2010, 04:24 AM   #1
andrewscs
LQ Newbie
 
Registered: Jul 2005
Posts: 20

Rep: Reputation: 0
questions with g++ linker


i've compiled libpdfdoc and placed the static library libpdfdoc-static.a in /usr/lib64/

i've written a small program(test.cpp) to test the library

Code:
#include <iostream>
#include "libpdfdoc.hh"

int main()
{
        pdf::Doc *doc = pdf::CreateDoc();
        std::cout << "Hello" << std::endl;
        return 0;
}
then i run the following and get the output :

Code:
$ g++ -I/home/usr/libpdf/include -c test.cpp
$ g++ -L/usr/lib64 -lpdfdoc_static test.o -o test
test.o: In function `main':
test.cpp:(.text+0x9): undefined reference to `pdf::CreateDoc()'
collect2: ld returned 1 exit status
can anyone tell me what is wrong? i even try placing the full path to the library(g++ /usr/lib64/libpdfdoc_static.a test.o -o test) but the same error shown..

i'm using Fedora 13 64bits..
 
Old 07-20-2010, 05:04 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by andrewscs View Post
Code:
$ g++ -I/home/usr/libpdf/include -c test.cpp
$ g++ -L/usr/lib64 -lpdfdoc_static test.o -o test
test.o: In function `main':
test.cpp:(.text+0x9): undefined reference to `pdf::CreateDoc()'
collect2: ld returned 1 exit status
can anyone tell me what is wrong? i even try placing the full path to the library(g++ /usr/lib64/libpdfdoc_static.a test.o -o test) but the same error shown..
Your problem is not where the library is - if the linker couldn't find it, you'd get something like "cannot find -lpdfdoc_static".

Your problem is most likely one of ordering. Try moving the -l... directive after test.o, like so:

Code:
$ g++ -L/usr/lib64 test.o -o test -lpdfdoc_static
 
Old 07-20-2010, 05:58 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by JohnGraham View Post
Try moving the -l... directive after test.o
I agree. In general the -l's must appear later on the command line than the inputs that depend on those -l's. test.o depends on -lpdfdoc_static, so -lpdfdoc_static must come later on the command line than test.o.
 
Old 07-20-2010, 07:39 AM   #4
andrewscs
LQ Newbie
 
Registered: Jul 2005
Posts: 20

Original Poster
Rep: Reputation: 0
it works... thank you so much..
by the way, where do you recommend i study more on the g++ ??
i'm new to g++...
 
Old 07-20-2010, 08:06 AM   #5
andrewscs
LQ Newbie
 
Registered: Jul 2005
Posts: 20

Original Poster
Rep: Reputation: 0
if i have a directory '/home/user/myLib' and '/home/user/myInclude'
how do i include both of these directories into the default search path and default include path of g++?
 
Old 07-21-2010, 04:30 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
are you using gnu make? (you don't need a makefile)
if not you should.


try this:
Code:
export LDFLAGS="-L /home/user/myLib"
export CXXFLAGS="-I /home/user/myInclude"
export LDLIBS="-lfdoc-static"
make test
note:
CXXFLAGS for C++
CFLAGS for C


it's probably not necessary to put your libs in the system lib
directory.
I wouldn't anyway.

Last edited by bigearsbilly; 07-21-2010 at 04:32 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] cryptic linker error (i really dont like linker errors); smeezekitty Programming 2 09-19-2009 02:21 AM
Assembly Linker ch4 Linux - Newbie 1 10-16-2006 04:50 PM
linker error pavan Programming 2 10-06-2005 01:58 AM
ld linker errors Ankit mittal Programming 1 09-30-2005 03:05 PM
Linker error eddydw Linux - General 0 09-20-2004 01:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration