# Use CMake generate a shared library .so which is to be used in Julia

**URL:** <https://discourse.julialang.org/t/use-cmake-generate-a-shared-library-so-which-is-to-be-used-in-julia/32197>\
**Category:** General Usage\
**Tags:** package, cxx\
**Created:** [December 12, 2019, 1:51pm UTC](https://discourse.julialang.org/t/use-cmake-generate-a-shared-library-so-which-is-to-be-used-in-julia/32197 "2019-12-12T13:51:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [December 12, 2019, 1:51pm UTC](https://discourse.julialang.org/t/use-cmake-generate-a-shared-library-so-which-is-to-be-used-in-julia/32197/1 "2019-12-12T13:51:40Z")

</div>

Following the example 3 this link, [Introduction to CMake by Example | derekmolloy.ie](http://derekmolloy.ie/hello-world-introductions-to-cmake/#Source_Code_for_this_Discussion), 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](https://github.com/JuliaInterop/Cxx.jl)  
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.

```julia
_ _ _(_)_ | 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?
