Why input-file-parameters order matters?

WU Jun quark@lihdd.net
Mon May 17 12:09:00 GMT 2010


I am sorry that I was not reading g++ man page carefully.

'g++ a.o -lb' will search library b after a.o. So a.o must be put in 
front of '-b' in previous case.

On 05/17/2010 03:26 PM, WU Jun wrote:
> I encounter a situation:
>
> g++ b.o a.o -o c -lboost_test_exec_monitor-mt
>
> is ok, while
>
> g++ -o c -lboost_test_exec_monitor-mt b.o a.o
>
> fails:
> a.o: In function `init_unit_test_suite(int, char**)':
> a.cpp:(.text+0x0): multiple definition of `init_unit_test_suite(int,
> char**)'
> /usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../libboost_test_exec_monitor-mt.a(test_main.o):(.text+0x70):
> first defined here
> ...
>
> It seems "a.o" must be before "-lboost_test_exec_monitor-mt".
> Why ?
>
> I have googled around and read g++ manual and haven't found really
> helpful information ...
>
> I'm using Archlinux i686, gcc 4.5.0 and 1.41.0.
> a.o and b.o are created by this shell script:
>
> cat > a.cpp << !
> #define BOOST_TEST_MAIN
> #include <boost/test/unit_test.hpp>
> #include "b.h"
>
> BOOST_AUTO_TEST_CASE( SomeTest ) {
> A a;
> BOOST_CHECK( a.get() == 3);
> }
> !
>
> cat > b.cpp << !
> #include "b.h"
> int A::get() {
> return 3;
> }
> !
>
> cat > b.h << !
> class A {
> public:
> int get();
> };
> !
>
> # compile
> g++ a.cpp -c -o a.o
> g++ b.cpp -c -o b.o
>
>



More information about the Gcc-help mailing list