Неопределенная ссылка, полученная из ссылок g ++ - PullRequest
1 голос
/ 21 февраля 2010

Я новичок в g ++ и Makefile. Я пытаюсь связать эту библиотеку BeBOP SMC, которая находится в моем каталоге lib. В каталоге lib находятся bebop_util и sparse_matrix_converter, которые уже были собраны без ошибок. Я вижу libbebop_util.a, libbebop_util.so в bebop_util и libsparse_matrix_converter.a, libsparse_matrix_converter.so в sparse_matrix_converter. Ниже приведен источник:

Makefile

CC=g++
CFLAGS=-c -Wall

test.out: test.o
    $(CC) -o test.out -Ilib/sparse_matrix_converter/include -Llib/bebop_util \
-Llib/sparse_matrix_converter -lbebop_util -lsparse_matrix_converter test.o

test.o: test.cpp
    $(CC) $(CFLAGS) -Ilib/sparse_matrix_converter/include test.cpp

clean:
    rm -f test.o test.out
<ч />

test.cpp

#include <bebop/smc/sparse_matrix.h>
#include <bebop/smc/sparse_matrix_ops.h>

int main(int argc, const char* argv[])
{
    struct sparse_matrix_t* A = load_sparse_matrix (MATRIX_MARKET, "sample_input");
    destroy_sparse_matrix(A);
    return 0;
}


Выход:
login3% make
g++ -c -Wall -Ilib/sparse_matrix_converter/include test.cpp
g++ -o test.out -Ilib/sparse_matrix_converter/include -Llib/bebop_util -Llib/sparse_matrix_converter -lbebop_util -lsparse_matrix_converter test.o
test.o: In function `main':
test.cpp:(.text+0x1a): undefined reference to `load_sparse_matrix(sparse_matrix_file_format_t, char const*)'
test.cpp:(.text+0x27): undefined reference to `destroy_sparse_matrix(sparse_matrix_t*)'
collect2: ld returned 1 exit status
make: *** [test.out] Error 1

Обратите внимание, что test.cpp зависит от sparse_matrix_converter, который зависит от bebop_util. Пожалуйста, дайте мне знать, какие ошибки я допустил? Спасибо.

Tom

1 Ответ

3 голосов
/ 21 февраля 2010

Код BeBOP выглядит как код на C, но не добавляет правильных средств защиты C ++. Окружите ваши включения extern "C", чтобы исправить это:

extern "C" {
#include <bebop/smc/sparse_matrix.h>
#include <bebop/smc/sparse_matrix_ops.h>
}
...