日期:2014-05-16  浏览次数:21378 次

奇怪的 Duplicate symbol
C/C++ code
cat test.cpp
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
using namespace std;
class C_A{
public:
    void fun_a(){cout<<"C_A::fun_a!\n";}
};
extern void testFun();
int main(){
    testFun();
    return 0;
}

C/C++ code
cat test2.cpp
#include <iostream>
using namespace std;

void testFun()
{
        cout<<"testFun()\n";
}

C/C++ code
cat Makefile
EXE=run
OBJS=test.o test2.o
DD=
CC=xlC
all:$(EXE)
$(EXE):$(OBJS)
        $(CC) -o $@ $(OBJS)
.SUFFIXES: .c .cpp .o
.c.o:
        $(CC) $(DD) -c $<
.cpp.o:
        $(CC) $(DD) -c $<
.PHONY: clean
clean:
        -rm *.o $(EXE)

编译时,提示
make
  xlC -c test.cpp
  xlC -c test2.cpp
  xlC -o run test.o test2.o
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ostream<char,std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char,std::char_traits<char> >&,const char*)
ld: 0711-224 WARNING: Duplicate symbol: .std::char_traits<char>::length(const char*)
ld: 0711-224 WARNING: Duplicate symbol: .std::ios_base::width() const
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ostream<char,std::char_traits<char> >::sentry::sentry(std::basic_ostream<char,std::char_traits<char> >&)
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ostream<char,std::char_traits<char> >::sentry::operator bool() const
ld: 0711-224 WARNING: Duplicate symbol: .std::ios_base::flags() const
ld: 0711-224 WARNING: Duplicate symbol: .std::char_traits<char>::eof()
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ios<char,std::char_traits<char> >::rdbuf() const
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ios<char,std::char_traits<char> >::fill() const
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_streambuf<char,std::char_traits<char> >::sputc(char)
ld: 0711-224 WARNING: Duplicate symbol: .std::char_traits<char>::eq_int_type(const int&,const int&)
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_streambuf<char,std::char_traits<char> >::sputn(const char*,int)
ld: 0711-224 WARNING: Duplicate symbol: .std::ios_base::width(int)
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ios<char,std::char_traits<char> >::setstate(int,bool)
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ostream<char,std::char_traits<char> >::sentry::~sentry()
ld: 0711-224 WARNING: Duplicate symbol: .strlen(const char*)
ld: 0711-224 WARNING: Duplicate symbol: .std::ios_base::rdstate() const
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ios<char,std::char_traits<char> >::clear(int,bool)
ld: 0711-224 WARNING: Duplicate symbol: .std::ios_base::good() const
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ios<char,std::char_traits<char> >::tie() const
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ostream<char,std::char_traits<char> >::flush()
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_ostream<char,std::char_traits<char> >::osfx()
ld: 0711-224 WARNING: Duplicate symbol: .std::basic_streambuf<char,std::char_traits<char> >::pptr() const
ld: 0711-224 WARNING: Duplicate symbol: .std: