Re: g++ error on Solaris/Sparc undefined reference to std::cout

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

 



Thank you for reply! Following I will explain the problem in more detail.
I compiled GMP, MPFR, MPC in each own directory and installed them all
in /lab/home/zuoqi/gcc32/gcc-gnu-ccs .
The configuration is as following:

#!/bin/sh
cd /lab/home/zuoqi/gcc32/build-gmp-gnu-ccs
rm -rf *
../gmp-5.0.1/configure --prefix=/lab/home/zuoqi/gcc32/gcc-gnu-ccs
--with-gnu-ld ABI=32
make -j 64
make check
make install

cd /lab/home/zuoqi/gcc32/build-mpfr-gnu-ccs
rm -rf *
../mpfr-3.0.0/configure --prefix=/lab/home/zuoqi/gcc32/gcc-gnu-ccs
--with-gnu-ld --with-gmp=/lab/home/zuoqi/gcc32/gcc-gnu-ccs ABI=32
make -j 64
make check
make install

cd /lab/home/zuoqi/gcc32/build-mpc-gnu-ccs
rm -rf *
../mpc-0.9/configure --prefix=/lab/home/zuoqi/gcc32/gcc-gnu-ccs
--with-gnu-ld --with-gmp=/lab/home/zuoqi/gcc32/gcc-gnu-ccs
--with-mpfr=/lab/home/zuoqi/gcc32/g
cc-gnu-ccs ABI=32
make -j 64
make check
make install
echo lib DONE!

Then I compiled GCC4.6.0 in its building directory, as following
#!/bin/sh
LD_LIBRARY_PATH=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
export LD_LIBRARY_PATH
cd /lab/home/zuoqi/gcc32/build-gcc-gnu-ccs
rm -rf *
../gcc-4.6.0/configure ABI=32
--prefix=/lab/home/zuoqi/gcc32/gcc-gnu-ccs --with-gnu-as
--with-as=/usr/local/bin/as --with-gnu-ld --with-ld=/usr/local/bin/ld
-
-enable-languages=c,c++,java
--with-gmp-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
--with-gmp-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib --with-mpfr-inc
lude=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
--with-mpfr-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
--with-mpc-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/incl
ude --with-mpc-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib --without-ppl
--without-cloog --enable-plugin --enable-lto
make -j 64
make check
make install
echo gcc DONE!

Without the LD_LIBRARY_PATH setting, I can't manage to compile.

Without ABI=32, GMP, MPFR, MPC will generate 64-bit libraries. When
building GCC4.6.0, there will be 32/64 problems.


To check my GCC, I tried as you suggested using "-v"

Before I set LD_LIBRARY_PATH, GCC4.6.0 can't find mpc.

-bash-3.00$ /lab/home/zuoqi/gcc32/gcc-gnu-ccs/bin/g++ hello.cpp
ld.so.1: cc1plus: fatal: libmpc.so.2: open failed: No such file or directory
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

the paths use -v are as following

-bash-3.00$ /lab/home/zuoqi/gcc32/gcc-gnu-ccs/bin/g++ hello.cpp -v
Using built-in specs.
COLLECT_GCC=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/bin/g++
COLLECT_LTO_WRAPPER=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/libexec/gcc/sparc-sun-solaris2.10/4.6.0/lto-wrapper
Target: sparc-sun-solaris2.10
Configured with: ../gcc-4.6.0/configure ABI=32
--prefix=/lab/home/zuoqi/gcc32/gcc-gnu-ccs --with-gnu-as
--with-as=/usr/local/bin/as --with-gnu-ld --with-ld=/usr/local/bin/ld
--enable-languages=c,c++,java
--with-gmp-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
--with-gmp-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
--with-mpfr-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
--with-mpfr-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
--with-mpc-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
--with-mpc-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib --without-ppl
--without-cloog --enable-plugin --enable-lto
Thread model: posix
gcc version 4.6.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mcpu=v9'
 /lab/home/zuoqi/gcc32/gcc-gnu-ccs/libexec/gcc/sparc-sun-solaris2.10/4.6.0/cc1plus
-quiet -v -D__sparcv8 hello.cpp -quiet -dumpbase hello.cpp -mcpu=v9
-auxbase hello -version -o /var/tmp//ccIuYmkf.s
ld.so.1: cc1plus: fatal: libmpc.so.2: open failed: No such file or directory
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

After I set LD_LIBRARY_PATH to /lab/home/zuoqi/gcc32/gcc-gnu-gcc/lib
-bash-3.00$ export LD_LIBRARY_PATH=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib

compile again, then mpc can be found. But the std::cout errors raise.

-bash-3.00$ /lab/home/zuoqi/gcc32/gcc-gnu-ccs/bin/g++ hello.cpp
/var/tmp//ccDqluzK.o: In function `main':
hello.cpp:(.text+0x20): undefined reference to `std::cout'
hello.cpp:(.text+0x24): undefined reference to `std::cout'
hello.cpp:(.text+0x48): undefined reference to
`std::basic_ostream<char, std::char_traits<char>
>::operator<<(std::basic_ostream<char, std::char_traits<char> >&
(*)(std::basic_ostream<char, std::char_traits<char> >&))'
collect2: ld returned 1 exit status

the paths checked by -v as following

-bash-3.00$ /lab/home/zuoqi/gcc32/gcc-gnu-ccs/bin/g++ hello.cpp -v
Using built-in specs.
COLLECT_GCC=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/bin/g++
COLLECT_LTO_WRAPPER=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/libexec/gcc/sparc-sun-solaris2.10/4.6.0/lto-wrapper
Target: sparc-sun-solaris2.10
Configured with: ../gcc-4.6.0/configure ABI=32
--prefix=/lab/home/zuoqi/gcc32/gcc-gnu-ccs --with-gnu-as
--with-as=/usr/local/bin/as --with-gnu-ld --with-ld=/usr/local/bin/ld
--enable-languages=c,c++,java
--with-gmp-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
--with-gmp-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
--with-mpfr-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
--with-mpfr-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
--with-mpc-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
--with-mpc-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib --without-ppl
--without-cloog --enable-plugin --enable-lto
Thread model: posix
gcc version 4.6.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mcpu=v9'
 /lab/home/zuoqi/gcc32/gcc-gnu-ccs/libexec/gcc/sparc-sun-solaris2.10/4.6.0/cc1plus
-quiet -v -D__sparcv8 hello.cpp -quiet -dumpbase hello.cpp -mcpu=v9
-auxbase hello -version -o /var/tmp//cc5PnTq6.s
GNU C++ (GCC) version 4.6.0 (sparc-sun-solaris2.10)
        compiled by GNU C version 4.6.0, GMP version 5.0.1, MPFR
version 3.0.0, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/../../../../sparc-sun-solaris2.10/include"
#include "..." search starts here:
#include <...> search starts here:
 /lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/../../../../include/c++/4.6.0
 /lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/../../../../include/c++/4.6.0/sparc-sun-solaris2.10
 /lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/../../../../include/c++/4.6.0/backward
 /lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/include
 /usr/local/include
 /lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
 /lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.6.0 (sparc-sun-solaris2.10)
        compiled by GNU C version 4.6.0, GMP version 5.0.1, MPFR
version 3.0.0, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 9f29d9ac5fbce03d716a8e16add774bc
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mcpu=v9'
 /usr/local/bin/as -v -V -Qy -s -xarch=v8plus -o /var/tmp//ccxgZ998.o
/var/tmp//cc5PnTq6.s
GNU assembler version 2.21 (sparc-sun-solaris2.10) using BFD version
(GNU Binutils) 2.21
COMPILER_PATH=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/libexec/gcc/sparc-sun-solaris2.10/4.6.0/:/lab/home/zuoqi/gcc32/gcc-gnu-ccs/libexec/gcc/sparc-sun-solaris2.10/4.6.0/:/lab/home/zuoqi/gcc32/gcc-gnu-ccs/libexec/gcc/sparc-sun-solaris2.10/:/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/:/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/:/usr/ccs/bin/
LIBRARY_PATH=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/:/usr/ccs/lib/:/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mcpu=v9'
 /lab/home/zuoqi/gcc32/gcc-gnu-ccs/libexec/gcc/sparc-sun-solaris2.10/4.6.0/collect2
-V -Y P,/usr/ccs/lib:/usr/lib -rpath-link /usr/lib -Qy
/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/crt1.o
/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/crti.o
/usr/ccs/lib/values-Xa.o
/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/crtbegin.o
-L/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0
-L/usr/ccs/lib -L/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/../../..
/var/tmp//ccxgZ998.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc -lc
/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/crtend.o
/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib/gcc/sparc-sun-solaris2.10/4.6.0/crtn.o
GNU ld (GNU Binutils) 2.21
  Supported emulations:
   elf32_sparc_sol2
   elf32_sparc
   elf64_sparc_sol2
   elf64_sparc
/var/tmp//ccxgZ998.o: In function `main':
hello.cpp:(.text+0x20): undefined reference to `std::cout'
hello.cpp:(.text+0x24): undefined reference to `std::cout'
hello.cpp:(.text+0x48): undefined reference to
`std::basic_ostream<char, std::char_traits<char>
>::operator<<(std::basic_ostream<char, std::char_traits<char> >&
(*)(std::basic_ostream<char, std::char_traits<char> >&))'
collect2: ld returned 1 exit status


2011/4/19 Axel Freyn <axel-freyn@xxxxxx>:
> Hi,
> On Tue, Apr 19, 2011 at 07:08:44AM -0400, Qi Zuo wrote:
>> Thank you for reply!
>>
>> >You configure the compiler *before* you build it, not after.
>>
>> Yes, I configured GCC before I built it. Just as following:
>> #!/bin/sh
>> LD_LIBRARY_PATH=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
>> export LD_LIBRARY_PATH
>> cd /lab/home/zuoqi/gcc32/build-gcc-gnu-ccs
>> rm -rf *
>> ../gcc-4.6.0/configure ABI=32
>> --prefix=/lab/home/zuoqi/gcc32/gcc-gnu-ccs --with-gnu-as
>> --with-as=/usr/local/bin/as --with-gnu-ld --with-ld=/usr/local/bin/ld
>> -
>> -enable-languages=c,c++,java
>> --with-gmp-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
>> --with-gmp-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib --with-mpfr-inc
>> lude=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/include
>> --with-mpfr-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
>> --with-mpc-include=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/incl
>> ude --with-mpc-lib=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib --without-ppl
>> --without-cloog --enable-plugin --enable-lto
>> make -j 64
>> make check
>> make install
>> echo gcc DONE!
>>
>>
>> > -bash-3.00$ export LD_LIBRARY_PATH=/lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
>> > -bash-3.00$ echo $LD_LIBRARY_PATH
>> > /lab/home/zuoqi/gcc32/gcc-gnu-ccs/lib
>> >
>> > Then, when I compile the hello.cpp program, I got unreferenced
>> > std::cout problem.
>>
>> > Those symbols should be defined in libstdc++, maybe there's a symbol
>> > versioning problem.
>> >
>> I'm not sure about this problem.
>> The version of libstdc++.so of GCC4.4.2 is libstdc++.so.6.0.13
>> The version of libstdc++.so of GCC4.6.0 is libstdc++.so.6.0.15
>>
>> Is this the problem??
> Probably not. In principle, g++ should automatically link to its "own"
> library. However, a first remark: the "LD_LIBRARY_PATH" is (as far as I
> know) not important here: it will be used when you RUN the program, in
> order to find then the correct dynamic library. Your problem appears
> however already at link time.
>
> Could you recompile the code, passing "-v" to the compiler?
> /lab/home/zuoqi/gcc32/gcc-gnu-ccs/bin/g++ -v hello.cpp
> With that, g++ will tell us all pathes and sub-commands it executes.
> Maybe then someone will see the problem.
>
> What I could imagine: I never tried "ABI=32" at configuration time --
> maybe your linker "ld" does not understand correctly 32 bit libraries?
> Or you have a mixture of 32bit and 64bit code/libraries, which can't be
> linked together (if libstdc++ would be a 32bit file, but g++ generates
> 64bit I would understand the undefined reference...)?
>
> Axel
>



-- 
Regards
Qi Zuo

School Of Computer Science and Technology
Beijng Institute of Technology, China, 100081



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux