# CxxWrap and visual C++ linkage error

**URL:** <https://discourse.julialang.org/t/cxxwrap-and-visual-c-linkage-error/27217>\
**Category:** General Usage\
**Tags:** cxx\
**Created:** [August 6, 2019, 2:05pm UTC](https://discourse.julialang.org/t/cxxwrap-and-visual-c-linkage-error/27217 "2019-08-06T14:05:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [August 6, 2019, 2:05pm UTC](https://discourse.julialang.org/t/cxxwrap-and-visual-c-linkage-error/27217/1 "2019-08-06T14:05:41Z")

</div>

I’ve been trying to use CxxWrap with the minimal example from the readme, using MS visual C 2017 (and 2015), CxxWrap 0.8.2 on Win10 64 bit and in both cases I’ve ended with

```julia
Creating library C:/Users/petr.hlavenka/.julia/packages/CxxWrap/sarOk/test/Debug/hello.lib and object C:/Users/petr.hlavenka/.julia/packages/CxxWrap/sarOk/test/Debug/hello.exp
2>hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public:__cdecl jlcxx::FunctionWrapperBase::FunctionWrapperBase(class jlcxx::Module *,struct _jl_datatype_t *)" (__imp_??0FunctionWrapperBase@jlcxx@@QEAA@PEAVModule@1@PEAU_jl_datatype_t@@@Z) referenced in function "public:__cdecl jlcxx::FunctionPtrWrapper<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::FunctionPtrWrapper<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class jlcxx::Module *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > (__cdecl*)(void))" (??0?$FunctionPtrWrapper@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$$V@jlcxx@@QEAA@PEAVModule@1@P6A?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ@Z)
2>hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual__cdecl jlcxx::FunctionWrapperBase::~FunctionWrapperBase(void)" (__imp_??1FunctionWrapperBase@jlcxx@@UEAA@XZ) referenced in function "int `public:__cdecl jlcxx::FunctionPtrWrapper<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::FunctionPtrWrapper<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class FunctionPtrWrapper<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::Module *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > (__cdecl*)(void))'::`1'::dtor$0" (?dtor$0@?0???0?$FunctionPtrWrapper@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$$V@jlcxx@@QEAA@PEAVModule@1@P6A?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ@Z@4HA)
2>hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void__cdecl jlcxx::FunctionWrapperBase::set_name(struct _jl_value_t *)" (__imp_?set_name@FunctionWrapperBase@jlcxx@@QEAAXPEAU_jl_value_t@@@Z) referenced in function "public: class jlcxx::FunctionWrapperBase &__cdecl jlcxx::Module::method<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > (__cdecl*)(void),bool)" (??$method@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$$V@Module@jlcxx@@QEAAAEAVFunctionWrapperBase@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@P6A?AV34@XZ_N@Z)
2>hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) protected: void__cdecl jlcxx::FunctionWrapperBase::set_pointer_indices(void)" (__imp_?set_pointer_indices@FunctionWrapperBase@jlcxx@@IEAAXXZ) referenced in function "public:__cdecl jlcxx::FunctionPtrWrapper<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::FunctionPtrWrapper<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class jlcxx::Module *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > (__cdecl*)(void))" (??0?$FunctionPtrWrapper@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$$V@jlcxx@@QEAA@PEAVModule@1@P6A?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ@Z)
2>hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void__cdecl jlcxx::Module::append_function(class jlcxx::FunctionWrapperBase *)" (__imp_?append_function@Module@jlcxx@@QEAAXPEAVFunctionWrapperBase@2@@Z) referenced in function "public: class jlcxx::FunctionWrapperBase &__cdecl jlcxx::Module::method<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > (__cdecl*)(void),bool)" (??$method@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$$V@Module@jlcxx@@QEAAAEAVFunctionWrapperBase@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@P6A?AV34@XZ_N@Z)
2>C:\Users\petr.hlavenka\.julia\packages\CxxWrap\sarOk\test\Debug\hello.dll : fatal error LNK1120: 5 unresolved externals
2>Done building project "hello.vcxproj" -- FAILED.

```

Even the project file generated with cmake (should be bullet-proof) failed with the same linker error.

I’ve reported this as a issue [CxxWrap.jl#156](https://github.com/JuliaInterop/CxxWrap.jl/issues/156)

After looking into the code for a while, what I don’t understand is the way the compiler should interpret lines that import class from a dll but some methods are overloaded (not virtual).  
e.g. in module.hpp  
`class JLCXX_API Module` that translates to `class __declspec(dllimport) Module`  
According to this [MSDN article](https://docs.microsoft.com/en-us/cpp/cpp/using-dllimport-and-dllexport-in-cpp-classes?view=vs-2019) it seems to me the code above should not be allowed with MSVC/Windows.  
Could someone explain to me the principle it uses so I can fix my code or CxxWrap.  
Do you know what is missing in my workflow? Is there a know bug?

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [August 6, 2019, 7:01pm UTC](https://discourse.julialang.org/t/cxxwrap-and-visual-c-linkage-error/27217/2 "2019-08-06T19:01:05Z")

</div>

I have a different [issue](https://github.com/JuliaInterop/CxxWrap.jl/issues/151), but my code works with previous version 0.8.1 of CxxWrap.jl. Maybe that is the easiest thing to test.

---

<div class="post-metadata">

**Author:** ![phlavenk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/phlavenk/32/1873_2.png) [@phlavenk](https://discourse.julialang.org/u/phlavenk)\
**Post date:** [August 7, 2019, 6:23am UTC](https://discourse.julialang.org/t/cxxwrap-and-visual-c-linkage-error/27217/3 "2019-08-07T06:23:00Z")

</div>

I’ve tried 0.8.1 with exactly the same result.  
@Tero_Frondelius do you compile with MSVC or are you using different compiler?

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [August 7, 2019, 9:47am UTC](https://discourse.julialang.org/t/cxxwrap-and-visual-c-linkage-error/27217/4 "2019-08-07T09:47:33Z")

</div>

I have only used BinaryBuilder.jl environment in my project. Here it is, if it helps: [https://github.com/TeroFrondelius/mgisBuilder](https://github.com/TeroFrondelius/mgisBuilder)
