Following the example 3 this link, Introduction to CMake by Example | derekmolloy.ie, I successfully generate a shared library with name listestStudent.so.
Then, following the example 8 of this link: GitHub - JuliaInterop/Cxx.jl: The Julia C++ Interface
I was trying to call the functionality of this shared library and then an error message is generated.
The following is a copy from julia Atom REPL.
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.2.0 (2019-08-20)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> using Cxx
julia> using Libdl
julia> const path_to_lib = "/home/devel/exploringBB/extras/cmake/studentlib_shared/build"
"/home/devel/exploringBB/extras/cmake/studentlib_shared/build"
julia> addHeaderDir(path_to_lib, kind = C_System)
julia> Libdl.dlopen(joinpath(path_to_lib, "libtestStudent.so"), Libdl.RTLD_GLOBAL)
Ptr{Nothing} @0x0000000003758ac0
julia> cxxinclude("/home/devel/exploringBB/extras/cmake/studentlib_shared/include/Student.h")
julia> student = @cxxnew Student("lucy")
ERROR: Got bad type information while compiling Cxx.CxxCore.CppNNS{Tuple{:Student}} (got String for argument 1)
Stacktrace:
[1] check_args at /home/devel/.julia/packages/Cxx/vxYtJ/src/codegen.jl:447 [inlined]
[2] _cppcall(::Type, ::Type, ::Bool, ::Bool, ::Tuple{DataType}) at /home/devel/.julia/packages/Cxx/vxYtJ/src/codegen.jl:516
[3] #s37#41(::Any, ::Any, ::Any, ::Any) at /home/devel/.julia/packages/Cxx/vxYtJ/src/codegen.jl:849
[4] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:524
[5] top-level scope at none:0
So, I double checked the process. I think it might be because of the -fPIC flag in the following command.
>> g++ -shared -fPIC ArrayMaker.cpp -o libArrayMaker.so
Does anyone know how to fix it?