Linking a library with main.cpp

Discussion in 'C++' started by =?ISO-8859-15?Q?Luigi_Malag=F2?=, Jan 28, 2007.

  1. Hello,
    i'm having a problem with "multiple definition error" linking a library.
    I have a program with a main. I have another program with classes and a
    main too. I created a library of the second program, after compiling, in
    this way:

    ar -r /path/lib/libtest.a ./Class1.o ./Class2.o ./Class3.o

    Notice that from the list I excluded ./main.o !
    then I copied all .h in a specific directory /path/include

    Then i compiled the first program adding -I/path/include
    and -L/path/lib and -ltest

    In the main of the first program, I only include and use some classes
    from the second program, I dont expect the first program to clash with
    the main of the second program!

    Of course I'm missing something, since I cannot compile the program, I
    get a multiple definition error:


    /path/lib/libbriantool.a(main.o): In function `main':
    main.cpp:(.text+0x70): multiple definition of `main'
    ../main.o:main.cpp:(.text+0x70): first defined here
    /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/bin/ld:
    Warning: size of symbol `main' changed from 337 in ./main.o to 3125 in
    /path/lib/libbriantool.a(main.o)
    collect2: ld returned 1 exit status
    make: *** [..] Error 1


    Thanks for your help,
    Luigi
    =?ISO-8859-15?Q?Luigi_Malag=F2?=, Jan 28, 2007
    #1
    1. Advertising

  2. =?ISO-8859-15?Q?Luigi_Malag=F2?=

    Grizlyk Guest

    Luigi Malagò wrote:
    >
    > /path/lib/libbriantool.a(main.o): In function `main':
    > main.cpp:(.text+0x70): multiple definition of `main'
    > ./main.o:main.cpp:(.text+0x70): first defined here
    > /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/bin/ld:
    > Warning: size of symbol `main' changed from 337 in ./main.o to 3125 in
    > /path/lib/libbriantool.a(main.o)
    > collect2: ld returned 1 exit status
    > make: *** [..] Error 1



    ask about "/path/lib/libbriantool.a" here news:gnu.g++.help

    --
    Maksim A Polyanin
    Grizlyk, Jan 28, 2007
    #2
    1. Advertising

  3. Grizlyk ha scritto:
    > Luigi Malagò wrote:
    >> /path/lib/libbriantool.a(main.o): In function `main':
    >> main.cpp:(.text+0x70): multiple definition of `main'
    >> ./main.o:main.cpp:(.text+0x70): first defined here
    >>

    /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/bin/ld:
    >> Warning: size of symbol `main' changed from 337 in ./main.o to 3125 in
    >> /path/lib/libbriantool.a(main.o)
    >> collect2: ld returned 1 exit status
    >> make: *** [..] Error 1

    >
    >
    > ask about "/path/lib/libbriantool.a" here news:gnu.g++.help



    Thanks a lot, i just realize the problem could be solved setting a
    specific option to the compiler/linker.

    I will post the message to that newsgroup if i wont be able to solve my
    problem


    Luigi
    =?ISO-8859-15?Q?Luigi_Malag=F2?=, Jan 29, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John M
    Replies:
    1
    Views:
    1,137
    Kumar Reddi
    May 29, 2005
  2. DrUg13
    Replies:
    1
    Views:
    470
    DrUg13
    Feb 10, 2004
  3. Alex Vinokur
    Replies:
    7
    Views:
    407
    Greg Comeau
    Nov 15, 2004
  4. Vinu
    Replies:
    9
    Views:
    617
  5. www.hitechskill.com
    Replies:
    0
    Views:
    1,343
    www.hitechskill.com
    Apr 9, 2006
Loading...

Share This Page