g++ trouble linking against archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I've got the following simple source files:

//Begin fun1.cpp
#include <iostream.h>
void fun1( ) { cout << "Exits in fun1( )\n"; }
//End fun1.cpp

//Begin fun2.cpp
#include <iostream.h>
void fun2( ) { cout << "Exits in fun2( )\n"; }
//End fun2.cpp

//Begin funmain.cpp
#include <iostream.h>
void fun1( );
int main( )
{
cout << "about to call fun1( )\n";
fun1( );
cout << "just called fun1( )\n";
return 0;
}
//End funmain.cpp

all of the source files are in the directory
/home/exits/moment/cpptest. I compile the two
functions like this:

g++ -c fun1.cpp
g++ -c fun2.cpp

I then archive the two resulting object files like
this:

ar -cr libfun.a fun1.o fun2.o

So far so good (I think) i've not got my library
containing the two functions. I can't seem to figure
out though how to link my main method agains the
archive. It seems this should work:

g++ -o fun -L/home/exits/moment/cpptest -lfun
funmain.cpp

but it doesn't instead g++ complains about an
undefined reference to fun1( ). If I just pop the .o
file on the command line when I compile/link main
everything is fine but I really need to get the
library stuff working. If anyone could point out what
I've done wrong, I'd really appreciate it. Thanks in
advance!

-exits


	
		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - You care about security. So do we. 
http://promotions.yahoo.com/new_mail

_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux