当我尝试构建我的应用程序时,我得到链接器错误undefined reference to (..)
。找不到的所有函数都是从meschach库导入的。在我看来,库已正确安装:
whereis libmeschach
libmeschach: /lib/libmeschach.so /usr/lib/libmeschach.so /lib64/libmeschach.so
我的SCons文件:
import os
import sys
import functools
PROJECT_ROOT = os.path.curdir
doc_path = functools.partial(os.path.join, PROJECT_ROOT, 'doc')
src_path = functools.partial(os.path.join, PROJECT_ROOT, 'src')
out_path = functools.partial(os.path.join, PROJECT_ROOT, 'build')
cpp_flags = {
'linux2' : '-Wall -Wextra -pedantic -fopenmp -O3',
'win32' : '/w /MD /openmp'
}
env = Environment(ENV=os.environ,CPPFLAGS=cpp_flags[sys.platform])
env.VariantDir(variant_dir=out_path(),src_dir=src_path())
env.Program(target=out_path('cholesky'), source=Glob(out_path('*.cpp')), LIBS=['m'])
我使用Arch Linux 64bit。
编辑:我用Makefile替换了SCons但仍然存在错误:
CC=g++
CFLAGS=-c -Wall -Wextra -pedantic -I./externals/include
LIB=./externals/lib/meschach.a -lm
all: cholesky
cholesky: cholesky.o equation.o testing.o profiler.o parallelCholeskyTest.o matrix.o
$(CC) cholesky.o equation.o testing.o profiler.o parallelCholeskyTest.o matrix.o -o
main $(LIB)
cholesky.o:
$(CC) $(CFLAGS) src/cholesky.cpp
equation.o: matrix.o
$(CC) $(CFLAGS) src/equation.cpp
matrix.o:
$(CC) $(CFLAGS) src/matrix.cpp
testing.o:
$(CC) $(CFLAGS) src/testing.cpp
profiler.o:
$(CC) $(CFLAGS) src/profiler.cpp
parallelCholeskyTest.o:
$(CC) $(CFLAGS) src/parallelCholeskyTest.cpp
答案 0 :(得分:1)
确定。我解决了此库不能作为C ++库包含在内,您必须使用#include
封装每个extern "C" { }
。您可以在此处找到有关此问题的更多信息:C-library not linking using gcc/g++