I have a question about using CMake to link the shared library.
After building OpenBLAS from source and install it succesfully. In /opt/OpenBLAS/include has header files and in /opt/OpenBLAS/lib has shared and static libraries.
If I have a toy program call cpp_gemm.cpp, I can build it by typing
g++ -o cpp_gemm cpp_gemm.cpp -I/opt/OpenBLAS/include -L/opt/OpenBLAS/lib -lopenblas
And execute it without error message.
But I want to use CMake to build it, so I write following rules in CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
project(CppGEMM)
include_directories(/opt/OpenBLAS/include)
link_directories(/opt/OpenBLAS/lib)
add_executable(cpp_gemm cpp_gemm.cpp)
target_link_libraries(cpp_gemm openblas)
After I create build folder and enter into it, I type
cmake ..
make
to build the program successfully. But I will get
Illegal instruction (core dumped)
after execute it.
After searching the related problems by Google search, I found that replace
link_directories(/opt/OpenBLAS/lib)
with
link_directories(/opt/OpenBLAS)
can solve my problem. That is, I can build the program successfully and execute it without the error message.
I'm confused, but I can not find any material to realize it. Can anyone tell me why this occurred? Many thanks!