gcc로 정적 라이브러리 연결이 잘 안되네요..

kkokdae의 이미지

예를 들어.

a.a b.a 라는 2개의 정적 라이브러리 파일이 있을때

gcc -o main main.o a.a b.a

이렇게 하려는데요,

다른건 에러 안나는거 같은데..

b.a 에서 사용하려는 함수가 도중에 a.a 안에 있는 함수를 호출 하는 경우에 대해 undefined reference to 가 나오네요 ㅠㅠ

어떻게 해야하죠?

kkokdae의 이미지

어느 정도 해결은 됬습니다.

gcc -o main main.o a.a b.a a.a

라고 참조되는 a.a를 뒤에다 한번더 써주니 되네요;;

근데 이거 말고 방법은 없을까요?

barmi의 이미지

말씀하신 내용이 해결 방법이긴 합니다.
gcc의 링크 순서는 오른쪽부터라고 알고 있습니다.
따라서, 끝에 한번 더 써주시지 말고, 순서만 b.a a.a 로 변경해도 될 겁니다.

oosap의 이미지

ld -o main main.o --start-group a.a b.a --end-group
gcc -o main main.o -Wl,--start-group,a.a,b.a,--end-group

ld -o main main.o -\( a.a b.a -\)
gcc -o main main.o -Wl,-\(,a.a,b.a,-\)

이렇게 해보세요..

--start-group, --end-group 혹은 -\(, -\) 사이의 스태틱라이브러리들은 한번만 스캔되는 기본 동작이 아니라 여러번 스캔하면서 심볼들을 찾는다고 합니다.
그래서 이런 정의되지 않은 심볼때문에 링킹되지 않을 때 유용하다고 하네요...

그런데 이 방법보다는 위엣분 처럼 의존하는 라이브러리를 순서대로 배치하는 걸 기억하고 그렇게 사용하는게 더 좋다고 생각합니다.
이렇게 배치할 때 어떤 라이브러리가 어떤 라이브러리에 의존하는지 기억하는데도 도움이 됩니다.

단, 순서대로 배치할 수 없는 경우(교차참조라고 하더군요) 즉, 서로가 서로를 참조하는 경우는 제가 소개해드린 옵션을 사용하는 것이 좋은 해결책이 된다고 합니다.

Thanks for being one of those who care for people and mankind.
I'd like to be one of those as well.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.