LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2902|回复: 1

g++链接错误,请问如何解决_link failed: Nonrepresentable section on output

[复制链接]
发表于 2008-3-12 17:39:35 | 显示全部楼层 |阅读模式
碰到一个g++链接错误啊.怎么解决呢?

1. Here, i use hello_a.cpp and hello.h to create a hello.a
>>>>>>>>OK
2.Then, i use hello.a to create hello.so
>>>>>>>>OK
3.Finally, i use main.cpp, hello.h and hello.so to create application test_so.
>>>>>>>>link error

The following is the code example.

////////////
////hello.h
/////////////////
#ifndef _HELLO_H
#define _HELLO_H

void hello(const char*name);

#endif


//////////////////
//////hello_a.cpp
//////////////
#include "hello.h"
#include <iostream>

void hello(const char*name)
{
std::cout<<name<<std::endl;
}

//////////////////
//////hello_so.cpp
//////////////
#include "hello.h"

//////////////////
//////main.cpp
//////////////
#include "hello.h"

#include <iostream>

int main()
{
std::cout<<"start main"<<std::endl;
hello("hello");
return 0;
}

##////////////////////////
##Makefile

all: test_so

test_so:hello_so
g++ main.cpp hello.so -o test_so

hello_so:hello_a
g++ -g -c hello_so.cpp -o hello_so.o
g++ -shared -o hello.so hello_so.o -Wl,-whole hello.a

hello_a:hello_a.o
ar -rc hello.a hello_a.o

hello_a.o:
g++ -g -c hello_a.cpp -o hello_a.o

clean:
rm *.o *.a *.so test_so

#################
######in Makefile the ' ' in command line shoube be replace by Tab

/////////////////////////////
//////////linker erro:
>>>>$ make
ar -rc hello.a hello_a.o
g++ -g -c hello_so.cpp -o hello_so.o
g++ -shared -o hello.so hello_so.o -Wl,-whole hello.a
g++ main.cpp hello.so -o test_so
/usr/bin/ld: BFD 2.17 Debian GNU/Linux assertion fail ../../bfd/elflink.c:6261
/usr/bin/ld: test_so: hidden symbol `__fini_array_end' in test_so is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make: *** [test_so] Error 1

///g++ version info
>>>>>>>>>> g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --with-tune=i686 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

//////////////
How can i solove the problem...??
 楼主| 发表于 2008-3-12 18:11:19 | 显示全部楼层
Makefile  错误,应该

g++ -shared -o hello.so hello_so.o -Wl,-whole hello.a ----->
g++ -shared -o hello.so hello_so.o -Wl,-whole hello.a -Wl,-no-whole-archive
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表