2014-09-22 130 views
1

我有以下的CMakeLists.txt:鏈接BLAS的錯誤與CMake的

cmake_minimum_required (VERSION 2.6) 
project (MTSOS) 

# Select flags. 
set(CMAKE_C_FLAGS "-std=c99") 

# Blas library 
find_package(BLAS REQUIRED) 

include_directories(${BLAS_INCLUDE_DIR}) 

add_executable (test_MTSOS test_MTSOS.c barrier_front.c dynamics_front.c 
MTSOS.c csparse.c) 

# Linking CImg dependencies. 
target_link_libraries (test_MTSOS m blas ${BLAS_LIBRARIES}) 

當我運行cmake ..

-- The C compiler identification is GNU 4.8.2 
-- The CXX compiler identification is GNU 4.8.2 
-- Check for working C compiler: /usr/bin/cc 
-- Check for working C compiler: /usr/bin/cc -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Check for working CXX compiler: /usr/bin/c++ 
-- Check for working CXX compiler: /usr/bin/c++ -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Looking for dgemm_ 
-- Looking for dgemm_ - found 
-- Looking for include file pthread.h 
-- Looking for include file pthread.h - found 
-- Looking for pthread_create 
-- Looking for pthread_create - not found 
-- Looking for pthread_create in pthreads 
-- Looking for pthread_create in pthreads - not found 
-- Looking for pthread_create in pthread 
-- Looking for pthread_create in pthread - found 
-- Found Threads: TRUE 
-- A library with BLAS API found. 
-- Configuring done 
-- Generating done 
-- Build files have been written to: /home/jabuntu14/Desktop/MTSOS/build 

然而,當我嘗試用make編譯:

Scanning dependencies of target test_MTSOS 
[ 20%] Building C object CMakeFiles/test_MTSOS.dir/test_MTSOS.c.o 
[ 40%] Building C object CMakeFiles/test_MTSOS.dir/barrier_front.c.o 
/home/jabuntu14/Desktop/MTSOS/barrier_front.c: In function ‘so_barrier’: 
/home/jabuntu14/Desktop/MTSOS/barrier_front.c:83:25: warning: implicit declaration of function ‘dsyr’ [-Wimplicit-function-declaration] 
         dsyr(uplo, &u_size, &alpha, &Df[i*U_size], &one, A, &u_size); 
         ^
[ 60%] Building C object CMakeFiles/test_MTSOS.dir/dynamics_front.c.o 
[ 80%] Building C object CMakeFiles/test_MTSOS.dir/MTSOS.c.o 
/home/jabuntu14/Desktop/MTSOS/MTSOS.c: In function ‘so_MakeA’: 
/home/jabuntu14/Desktop/MTSOS/MTSOS.c:1561:13: warning: implicit declaration of function ‘dgemv’ [-Wimplicit-function-declaration] 
      dgemv(chn, &m_m, &n_m, &one, &M_dynamics[i*State_size*State_size], &m_m, &S_prime[i*State_size], &p_m, &zero, datam, &p_m); 
      ^
[100%] Building C object CMakeFiles/test_MTSOS.dir/csparse.c.o 
Linking C executable test_MTSOS 
CMakeFiles/test_MTSOS.dir/barrier_front.c.o: In function `so_barrier': 
barrier_front.c:(.text+0x4a7): undefined reference to `dsyr' 
CMakeFiles/test_MTSOS.dir/MTSOS.c.o: In function `so_MakeA': 
MTSOS.c:(.text+0x5e41): undefined reference to `dgemv' 
MTSOS.c:(.text+0x5ee4): undefined reference to `dgemv' 
MTSOS.c:(.text+0x5f87): undefined reference to `dgemv' 
collect2: error: ld returned 1 exit status 
make[2]: *** [test_MTSOS] Error 1 
make[1]: *** [CMakeFiles/test_MTSOS.dir/all] Error 2 
make: *** [all] Error 2 

所以我有一個鏈接問題,但我不明白爲什麼。歡迎任何幫助。謝謝!!

注意:在Ubuntu 14.04下使用GCC工作。在.c文件中,我包含#include "cblas.h",正如我在其他網站中看到的。

編輯:運行使VERBOSE = 1的輸出是:

[email protected]:~/Desktop/MTSOS/build$ make VERBOSE=1 
/usr/bin/cmake -H/home/jabuntu14/Desktop/MTSOS -B/home/jabuntu14/Desktop/MTSOS/build --check-build-system CMakeFiles/Makefile.cmake 0 
/usr/bin/cmake -E cmake_progress_start /home/jabuntu14/Desktop/MTSOS/build/CMakeFiles /home/jabuntu14/Desktop/MTSOS/build/CMakeFiles/progress.marks 
make -f CMakeFiles/Makefile2 all 
make[1]: Entering directory `/home/jabuntu14/Desktop/MTSOS/build' 
make -f CMakeFiles/test_MTSOS.dir/build.make CMakeFiles/test_MTSOS.dir/depend 
make[2]: Entering directory `/home/jabuntu14/Desktop/MTSOS/build' 
cd /home/jabuntu14/Desktop/MTSOS/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/jabuntu14/Desktop/MTSOS /home/jabuntu14/Desktop/MTSOS /home/jabuntu14/Desktop/MTSOS/build /home/jabuntu14/Desktop/MTSOS/build /home/jabuntu14/Desktop/MTSOS/build/CMakeFiles/test_MTSOS.dir/DependInfo.cmake --color= 
make[2]: Leaving directory `/home/jabuntu14/Desktop/MTSOS/build' 
make -f CMakeFiles/test_MTSOS.dir/build.make CMakeFiles/test_MTSOS.dir/build 
make[2]: Entering directory `/home/jabuntu14/Desktop/MTSOS/build' 
Linking C executable test_MTSOS 
/usr/bin/cmake -E cmake_link_script CMakeFiles/test_MTSOS.dir/link.txt --verbose=1 
/usr/bin/cc -std=c99 CMakeFiles/test_MTSOS.dir/test_MTSOS.c.o CMakeFiles/test_MTSOS.dir/barrier_front.c.o CMakeFiles/test_MTSOS.dir/dynamics_front.c.o CMakeFiles/test_MTSOS.dir/MTSOS.c.o CMakeFiles/test_MTSOS.dir/csparse.c.o -o test_MTSOS -rdynamic -lm -lblas -lf77blas -latlas 
CMakeFiles/test_MTSOS.dir/barrier_front.c.o: In function `so_barrier': 
barrier_front.c:(.text+0x4a7): undefined reference to `dsyr' 
CMakeFiles/test_MTSOS.dir/MTSOS.c.o: In function `so_MakeA': 
MTSOS.c:(.text+0x5e41): undefined reference to `dgemv' 
MTSOS.c:(.text+0x5ee4): undefined reference to `dgemv' 
MTSOS.c:(.text+0x5f87): undefined reference to `dgemv' 
collect2: error: ld returned 1 exit status 
make[2]: *** [test_MTSOS] Error 1 
make[2]: Leaving directory `/home/jabuntu14/Desktop/MTSOS/build' 
make[1]: *** [CMakeFiles/test_MTSOS.dir/all] Error 2 
make[1]: Leaving directory `/home/jabuntu14/Desktop/MTSOS/build' 
make: *** [all] Error 2 
+0

請'讓VERBOSE = 1'運行,並告訴我們使用的全'ld'命令。 – Peter 2014-09-23 09:24:31

+0

可能的重複[什麼是未定義的引用/未解析的外部符號錯誤,以及如何解決它?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-符號錯誤和怎麼辦我修復) – Peter 2014-09-23 09:26:44

+0

它不是該帖子的副本,它只是一個特殊情況。我沒有任何其他圖書館的這個錯誤。 – 2014-09-23 17:27:07

回答

0

在標準BLAS庫的功能是

dgemv_ 

代替

dgemv 

如在錯誤顯示,注意尾部的下劃線。 所以你可能在你的代碼中調用了dgemv()而不是dgemv_(),改變了這一點,那麼你應該沒問題。

(我有我在那裏使用的代碼有一些像#define dgemv_ dgemv同樣的問題)