简体   繁体   中英

Linker error when building an application with meschach library

When I try to build my application I get linker error undefined reference to (..) . All functions that were not found are imported from meschach library. In my opinion library is properly installed:

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

My SCons file:

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.

Edit: I replaced SCons with Makefile but error still remains:

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" { } . Here you can find more about this issue: C-library not linking using gcc/g++

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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