*.o를 링크하면 되고 라이브러리를 만들면 안됩니다.

ftfuture의 이미지

환경은 SunOS 5.8 입니다. 신기하게도.. 해당 루틴의 오브젝트 파일을 바로 링크하면 되는데
라이브러리를 만들면 링크에러가 납니다.
문제되는 부분만 추출하였습니다.
teststat.* 라이브러리로 만들 루틴입니다. test_test.cc 테스트 프로그램입니다.

teststat.h

#include < string>
#include < map>
 
class teststat
{
public:
    typedef std::map < std::string, int, std::less< std::string>, std::allocator< std::string> > testmap;
    testmap test_map;
 
    teststat();
    ~teststat();
 
}; // class teststat

teststat.cc
#include < teststat.h>
 
teststat::teststat()
{
    return;
}
 
teststat::~teststat()
{
    return;
}

test_test.cc

#include < teststat.h>
 
int main(void)
{
    class teststat stat1;
}

Makefile

test :
    CC -c teststat.cc -I.
    ar rv libtestlib.a teststat.o
#   CC -o test_test test_test.cc -I. -L. -ltestlib
    CC -o test_test test_test.cc teststat.o -I. 

Error Code

__rwstd::__rb_tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,__rwstd::__select1st<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::iterator __rwstd::__rb_tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,__rwstd::__select1st<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::erase(__rwstd::__rb_tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,__rwstd::__select1st<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::iterator,__rwstd::__rb_tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,__rwstd::__select1st<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::iterator) ./libtestlib.a(teststat.o)
void __rwstd::__rb_tree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,__rwstd::__select1st<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,int>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::__deallocate_buffers() ./libtestlib.a(teststat.o)
ftfuture의 이미지

< code > 로 묶어도 코드가 깨지네요.. 일단 한칸 띄기 신공으로 ㅋㅋ 돌려보실때는 붙여서 해보세요..

chunsj의 이미지

라이브러리를 링크할 때 -lstl 같은 식이나 -lstdc++ 같은 식(정확한 라이브러리 이름을 몰라서) 해도 안되나요?

ftfuture의 이미지

아~ 일단 답변 감사드립니다.
object 파일을 바로 링크를 하면 정상동작 되는 걸로 봐서는 필요없는 것 같습니다.
그리고 서드파티 인지 -lrwtool 인가 하는 걸로 링크를 했는데 안되네요..

klyx의 이미지

라이브러리를 만들때와 실행파일을 만들때는 컴파일러가 자동으로넣어주는 링크옵션이 다릅니다.
오브젝트로 바로 링크할때는 바로 실행파일을 만들기 때문에 자동을 들어가지만 main함수를 제외하고 라이브러리로 만들땐 빠져서 빌드가 안되는 경우가 자주 있습니다.
한번 직접 링크옵션을 줘보세요.

ftfuture의 이미지

그럴 수도 있겠네요..
답변 감사드립니다..

옵션을 찾아보겠습니다.
혹시 괞찮으시면 예를 들어주시면 감사하겠습니다. ^^

ymir의 이미지

Quote:

test :
CC -c teststat.cc -I.
ar rv libtestlib.a teststat.o
# CC -o test_test test_test.cc -I. -L. -ltestlib
CC -o test_test test_test.cc teststat.o -I.

libtestlib.a 는 static library 인데, linker 에는 shared library 로 지정해주셨네요. ??

libtestlib 을 shared library 로 빌드해야, link 옵션이 맞을 것 같은데요.

대충 아래와 같은 식으로 한 번 빌드해 보시면 어찌 되는지..?

test :
    gcc -c teststat.cc -I. -fPIC
    /usr/ccs/bin/ld -dy -b -G -o libtestlib.so teststat.o
    gcc -o test_test test_test.cc -I. -L. -ltestlib

* shared object 만드는 명령을 엉뚱한 걸 썼네요.. (수정)

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

ftfuture의 이미지

음.. 어느부분이 shared library로 지정된건가요? 정적으로 저렇게 써도 문제가 없는데요..
-lname
Links with object library libname.so or libname.a (for
ld(1)). The order of libraries in the command line is
important, as symbols are resolved from left to right.
This option must follow the sourcefile.

(libname.so, ㅣlibname.a 의 name부분에 밑줄이 있습니다.. 위에 -l 다음에 오는 name이겠죠.. ^^)
입니다..

음.. 말씀하신대로 해봐도 똑같은 증상이 일어납니다..

ymir의 이미지

static 은 object 와 함께 link 하던 버릇이 있어 착각한 것 같습니다.. ;;;

안쓰는 Sun 장비 하나 있길래 한번 빌드해 봤는데..
shared 로 build 하면 비슷한 에러가 나는데...
static 으로 build 하면 teststat::teststat() 이 undefiend symbol 이 나오는군요.
nm 으로 찍어봐도 해당 symbol 은 안 보입니다.

static:
        CC -o teststat.o -I. -c teststat.cc
        ar rv libteststat.a teststat.o
        CC -o test_test -I. -L. -lteststat test_test.cc
 
shared:
        CC -dy -G -o teststat.o -I. -c teststat.cc
        /usr/ccs/bin/ld -dy -b -G -o libteststat.so teststat.o
        CC -o test_test -I. -L. -lteststat test_test.cc
 
clean:
        /bin/rm -f *.so *.a *.o test_test

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

ymir의 이미지

C++ User's Guide 보고 Makefile 수정해 봤는데..
static 의 경우에는 위와 동일하게 method 가 undefined 떨어지고..
shared 의 경우에는 그냥 컴파일 되는군요... ;;

static:
        CC -o teststat.o -I. -c teststat.cc
        CC -xar -o libteststat.a teststat.o
        CC -o test_test -I. -L. -lteststat test_test.cc
 
shared:
        CC -G -I. -o libteststat.so -h libteststat.so -Kpic teststat.cc
        CC -o test_test -I. -L. -lteststat test_test.cc

장비는 Sun 5.8 sparc 이고, 컴파일러는.. 무려 Forte6 U2 네요.. ;;;;

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

ftfuture의 이미지

std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()./libtestlib.so
operator delete(void*)              ./libtestlib.so
__gxx_personality_v0                /var/tmp//ccYPgLtl.o
ld: 치명적: 기호 참조 오류, test_test에 출력이 기록되지 않음

에러가 나네요..

cwryu의 이미지

링크할 때 c++로.

직접 라이브러리 이름을 -lstdc++ 식으로 지정해도 될 텐데 SunOS니 이름이 다를 지도 모르겠군요.

ftfuture의 이미지

Solaris환경의 Forte6 C++ 컴파일러 입니다.. 그래서 그런지.. ar을 사용해서는 안됩니다..

    CC -c teststat.cc -I.
    CC -xar -o libtestlib.a teststat.o
#   ar rv libtestlib.a teststat.o
#   ranlib libtestlib.a
    CC -o test_test test_test.cc -I. -L. -ltestlib

/opt 폴더를 다 뒤졌더니 html로 된 매뉴얼이 나오더군요..
어쩃든 댓글 달아주신분들 사랑해요 ^^;;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.