g++ undefined reference 오류

sllsls의 이미지

CentOS-6.3 버전을 쓰고 있습니다.
m4ri 라는 수학 관련된 코드들을 리눅스상에서 돌리고 싶어서 돌리려고하는데
윈도우 비주얼에서는 잘 돌아가는 소스코드를 그대로 긁어서 리눅스에서 돌렸는데 참조하지 못한다는 에러를 나타내고 있습니다.
test.cpp 파일에는 헤더파일 3개가 include 되있는데 그 중 한 개의 헤더파일은 모든 헤더파일들을 include 하도록 되어있어서 서로 가지가 쳐져있는 상황입니다. 그런데 그 함수들을 참조하지 못하고 자꾸 에러를 만들어냅니다.
도와주세요. 잘 이해가 안되신다면 소스파일 전체를 압축해서 드릴테니 이메일을 남겨주세요.
꼭 리눅스 상에서 돌려야됩니다.

/tmp/ccmSmVOh.o: In function `test_pluq_solve_left(int, int, int, int)':
test.cpp:(.text+0x19): undefined reference to `mzd_init'
test.cpp:(.text+0x30): undefined reference to `mzd_init'
test.cpp:(.text+0x3e): undefined reference to `mzd_randomize'
test.cpp:(.text+0x49): undefined reference to `mzd_randomize'
test.cpp:(.text+0x74): undefined reference to `mzd_init_window'
test.cpp:(.text+0xa2): undefined reference to `mzd_init_window'
test.cpp:(.text+0xb8): undefined reference to `mzd_init'
test.cpp:(.text+0x264): undefined reference to `mzd_copy'
test.cpp:(.text+0x276): undefined reference to `mzd_echelonize'
test.cpp:(.text+0x2aa): undefined reference to `mzd_free'
test.cpp:(.text+0x2bd): undefined reference to `mzd_copy'
test.cpp:(.text+0x2df): undefined reference to `mzd_solve_left'
test.cpp:(.text+0x2f6): undefined reference to `mzd_init'
test.cpp:(.text+0x430): undefined reference to `mzd_mul'
test.cpp:(.text+0x449): undefined reference to `mzd_add'
test.cpp:(.text+0x45f): undefined reference to `mzd_is_zero'
test.cpp:(.text+0x48e): undefined reference to `mzd_free'
test.cpp:(.text+0x496): undefined reference to `mzd_free'
test.cpp:(.text+0x49e): undefined reference to `mzd_free'
test.cpp:(.text+0x4a9): undefined reference to `mzd_free'
test.cpp:(.text+0x4b4): undefined reference to `mzd_free'
/tmp/ccmSmVOh.o:test.cpp:(.text+0x4bf): more undefined references to `mzd_free' follow
/tmp/ccmSmVOh.o: In function `main':
test.cpp:(.text+0x51d): undefined reference to `m4ri_build_all_codes'
test.cpp:(.text+0x573): undefined reference to `m4ri_destroy_all_codes'
collect2: ld returned 1 exit status

익명 사용자의 이미지

참조는 링크 문제입니다. m4ri 라이브러리를 설치하시고 gcc에 적당한 -l 옵션을 주어서 컴파일 하세요.

sllsls의 이미지

[user1@localhost Test]$ ls
brilliantrussian.cpp io.cpp mzd.h solve.o
brilliantrussian.h io.cpp~ mzd.o strassen.cpp
brilliantrussian.o io.h mzp.cpp strassen.h
config.h.in io.o mzp.h strassen.o
debug_dump.cpp m4ri_config.h mzp.o test.cpp
debug_dump.h m4ri.h parity.h test.cpp~
debug_dump.o misc.cpp ple.cpp test.o
Doxyfile misc.h ple.h triangular.cpp
echelonform.cpp misc.o ple.o triangular.h
echelonform.h mmc.cpp ple_russian.cpp triangular.o
echelonform.o mmc.h ple_russian.h triangular_russian.cpp
graycode.cpp mmc.o ple_russian.o triangular_russian.h
graycode.h mzd.cpp solve.cpp triangular_russian.o
graycode.o mzd.cpp~ solve.h xor.h
[user1@localhost Test]$ pwd
/home/user1/Desktop/Test

현재 이렇게 파일들이 있고

g++ -o test1 *.o 를 입력하면 위에서 질문한 에러가 뜹니다..

-l 옵션을 붙이라고 하셔서 해보았는데 정확히 어떻게 붙여야 하는지 잘모르겠습니다.

g++ -o test1 *.o -l /home/user1/Desktop/Test 를 해도 안되고 /usr/bin/ld : cannot find 오류가 뜨네요...

상세하게 부탁드리겠습니다ㅠㅠㅠㅠ

익명 사용자의 이미지

비쥬얼스튜디오는 프로젝트 파일 이라는것이 있어서 각 소스들을 어떻게 컴파일하고 링크하는지가 나와있습니다.
리눅스에서 프로젝트파일 비슷한 역할을 하는것이 Makefile 입니다. CMake라고 Makefile 생성기가 있는데 이것을 배우시는것이 더 편할수도 있습니다.
프로젝트파일 참조해서 해당내용을 CMake로 재작성 하시던가 해야 합니다.
변환기도 있긴 한데 저는 써본적이 없어서 잘 모르겠습니다.

정리하자면.. 비쥬얼스튜디오에서 돌아가던 프로젝트를 g++로 컴파일 하는것은 컴파일/링크 구조를 잘 모르는 초보자에게는 어려운 일이고, 어느정도 공부가 필요한 일입니다.

댓글 달기

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