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 11-03-2004, 03:51 PM   #1
tjm
Member
 
Registered: Oct 2002
Posts: 55

Rep: Reputation: 15
g++ problem


Hi,

I have a relatively simple project I'm trying to compile.

I can compile it easily by hand, but I cannot convince KDevelop to compile it for me.
I have narrowed the error down to problems involving dumping the .o files created by g++ into a "library" with ar.

Below are two scripts which illustrate the problem. The first script works, the second one doesn't... why?

----------------- SCRIPT 1 -- WORKS!!! ---------------------------

g++ -Iscanner/ -Iparser/ -Icommon/ -Isemantics/ -c common/*cpp
g++ -Iscanner/ -Iparser/ -Icommon/ -Isemantics/ -c parser/*cpp
g++ -Iscanner/ -Iparser/ -Icommon/ -Isemantics/ -c scanner/*cpp
g++ -Iscanner/ -Iparser/ -Icommon/ -Isemantics/ -c semantics/*cpp
g++ -Iscanner/ -Iparser/ -Icommon/ -Isemantics/ *o mincc.cpp -o mincc


------------------ SCRIPT 2 -- BROKEN ---------------------------

cd common
g++ -I../scanner/ -I../parser/ -I../semantics/ -c *cpp
ar cru libcommon.a *o
ranlib libcommon.a
cd ..
cd parser
g++ -I../scanner/ -I../common/ -I../semantics/ -c *cpp
ar cru libparser.a *o
ranlib libparser.a
cd ..
cd scanner
g++ -I../parser/ -I../common/ -I../semantics/ -c *cpp
ar cru libscanner.a *o
ranlib libscanner.a
cd ..
cd semantics
g++ -I../scanner/ -I../parser/ -I../common/ -c *cpp
ar cru libsemantics.a *o
ranlib libsemantics.a
cd ..
g++ -Iscanner/ -Iparser/ -Icommon/ -Isemantics/ -c mincc.cpp
g++ semantics/libsemantics.a parser/libparser.a scanner/libscanner.a common/libcommon.a mincc.o -o mincc

My understanding was that ar would just "tar" the .o files together, thus the two should be equivalent... this is not the case.

Why?
 
Old 11-03-2004, 05:08 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I haven't used ar manually/explicitly, but wouldn't
it require the file to ar together be in the same directory?
If you keep changing directories without mv'ing the
file as you walk along, how can it ar it?



Cheers,
Tink
 
Old 11-03-2004, 06:34 PM   #3
tjm
Member
 
Registered: Oct 2002
Posts: 55

Original Poster
Rep: Reputation: 15
nope
the ar command is working since it cd's into each directory before the ar.
I am basically mimicking the effect of autotools as managed by KDevelop.

What I don't understand is why an ar file containing .o files is different from the compiler's perspective than just the .os.

I can, for instance, keep the .o files in the sub-directories and end the compile with

g++ common/*o scanner/*o parser/*o semantics/*o mincc.o -o mincc

and all is good... but the equivalent with ar'd .o files doesn't work

g++ common/libcommon.a scanner/libscanner.a parser/libparser.a semantics/libsemantics.a mincc.o -o mincc

causes unresolved references.
 
  


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
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

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

All times are GMT -5. The time now is 01:46 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