简体   繁体   English

使用Meschach库构建应用程序时出现链接器错误

[英]Linker error when building an application with meschach library

When I try to build my application I get linker error undefined reference to (..) . 当我尝试构建我的应用程序时,出现链接器错误undefined reference to (..) All functions that were not found are imported from meschach library. 未找到的所有功能均从meschach库中导入。 In my opinion library is properly installed: 我认为库已正确安装:

whereis libmeschach
libmeschach: /lib/libmeschach.so /usr/lib/libmeschach.so /lib64/libmeschach.so

My SCons file: 我的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'])

I use Arch Linux 64bit. 我使用Arch Linux 64bit。

Edit: I replaced SCons with Makefile but error still remains: 编辑:我用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

Ok. 好。 I solved it. 我解决了 This library cannot be included as a C++ library and you have to wrap each #include with extern "C" { } . 该库不能作为C ++库包含在内,您必须使用extern "C" { }包装每个#include Here you can find more about this issue: C-library not linking using gcc/g++ 在这里您可以找到有关此问题的更多信息: C库未使用gcc / g ++进行链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM