Ubuntu18.04,想试一下手册“嵌入Julia”一章中的例子:
https://docs.juliacn.com/latest/manual/embedding/#高级别嵌入-1
用gcc编译、链接成功,但是运行出错:
hl@hl-MACHR-WX9:~/Julia/ccallJulia/build$ export JULIA_DIR="/home/hl/julia-1.3.0-rc1"
hl@hl-MACHR-WX9:~/Julia/ccallJulia$ gcc -o HelloJulia -fPIC -I$JULIA_DIR/include/julia -L$JULIA_DIR/lib callJulia.c -ljulia $JULIA_DIR/lib/julia/libstdc++.so.6
hl@hl-MACHR-WX9:~/Julia/ccallJulia$ ./HelloJulia
./HelloJulia: error while loading shared libraries: libjulia.so.1: cannot open shared object file: No such file or directory
用cmake能编译但是链接不过:
hl@hl-MACHR-WX9:~/Julia/ccallJulia/build$ cmake …
正常。但是 make出错了:
hl@hl-MACHR-WX9:~/Julia/ccallJulia/build$ make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hl/Julia/ccallJulia/build
Scanning dependencies of target HelloJulia
[ 50%] Building CXX object CMakeFiles/HelloJulia.dir/CallJulia.cpp.o
[100%] Linking CXX executable HelloJulia
CMakeFiles/HelloJulia.dir/CallJulia.cpp.o:在函数‘main’中:
/home/hl/Julia/ccallJulia/CallJulia.cpp:10:对‘jl_init__threading’未定义的引用
/home/hl/Julia/ccallJulia/CallJulia.cpp:12:对‘jl_eval_string’未定义的引用
/home/hl/Julia/ccallJulia/CallJulia.cpp:14:对‘jl_atexit_hook’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/HelloJulia.dir/build.make:95: recipe for target 'HelloJulia' failed
make[2]: *** [HelloJulia] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/HelloJulia.dir/all' failed
make[1]: *** [CMakeFiles/HelloJulia.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
CMakeLists.txt 是这么写的:
# 声明要求的 cmake 最低版本
cmake_minimum_required(VERSION 2.8)
# 声明一个 cmake 工程
project(HelloJulia)
# 设置编译模式
set(CMAKE_BUILD_TYPE "Debug")
set(JULIA_INC_DIR "/home/hl/julia-1.3.0-rc1/include/julia")
set(JULIA_LIB_DIR "/home/hl/julia-1.3.0-rc1/lib")
include_directories(${JULIA_INC_DIR})
link_directories(${JULIA_LIB_DIR})
# 添加一个可执行程序
# 语法:add_executable( 程序名 源代码文件 )
add_executable(HelloJulia CallJulia.cpp)
# 将库文件链接到可执行程序上
target_link_libraries(HelloJulia ${JULIA_LIB_DIR}/julia/libstdc++.so.6)