noio
noio

Reputation: 5812

glib in c++ on Visual Studio 2013

I'm trying to compile a C++ project that includes the C library SkelTrack which uses glib

Now, I get a whole bunch of the following errors:

LNK2019: unresolved external symbol _g_slice_alloc referenced in function _pqueue_new   C:\....\pqueue.obj
LNK2019: unresolved external symbol _g_error_new referenced in function _skeltrack_skeleton_track_joints_sync skeltrack-skeleton.obj 
LNK2019: unresolved external symbol _g_mutex_init referenced in function _skeltrack_skeleton_init skeltrack-skeleton.obj 
LNK2019: unresolved external symbol _g_mutex_clear referenced in function _skeltrack_skeleton_finalize    skeltrack-skeleton.obj 
LNK2019: unresolved external symbol _g_mutex_lock referenced in function _skeltrack_skeleton_track_joints skeltrack-skeleton.obj 
LNK2019: unresolved external symbol _g_mutex_unlock referenced in function _skeltrack_skeleton_track_joints   skeltrack-skeleton.obj 
LNK2019: unresolved external symbol _g_once_init_enter referenced in function _skeltrack_skeleton_get_type    skeltrack-skeleton.obj 
LNK2019: unresolved external symbol _g_once_init_leave referenced in function _skeltrack_skeleton_get_type    skeltrack-skeleton.obj 

Link to SkelTrack code referencing glib: https://github.com/joaquimrocha/Skeltrack/blob/master/skeltrack/pqueue.c#L34

I must say that my understanding of the compilation process—especially on Windows—is quite vague, but here are some points of what I think is relevant information:

EDIT

EDIT 2

I have uninstalled the NuGet glib, downloaded glib for Win32 manually and added the include and lib to the project config (C/C++ Additional Include and VC++ Library Directories, respectively).

I got all kinds of syntax errors like:

C2143: syntax error : missing '{' before 'const'    c:\[....]\glib-dev\include\glib-2.0\glib\gutils.h   122 

But they were fixed using this tip:

In gutils.h lines 82 and 122, and in gstring.h line 129, change "static inline" to "static __inline".

And now I'm back to the unresolved external errors.

EDIT: ANSWER?

I was forgetting to add glib-2.0.lib, gio-2.0.lib, etc. to

Linker > Input > Additional Dependencies

Upvotes: 1

Views: 4542

Answers (1)

user1350184
user1350184

Reputation:

I had a similar fight with Visual Studio 2015, and I managed to get the NuGet package working; here's what I did:

Step 1 (Prerequisites)

  • Install the glib NuGet package.
  • Create a directory where you add glibconfig.h (I added it to lib\Glib23\include).

Step 2 (Project Properties)

  • Go to the "VC++ Directories" in Configuration Properties and add the following to "Library References":

    $(SolutionDir)packages\glib.2.36.2.11\build\native\lib\v110\$(Platform)\$(Configuration)\dynamic
    
  • In "C/C++" add the following to "Additional Include Directories":

    $(SolutionDir)lib\Glib23\include
    $(SolutionDir)packages\glib.2.36.2.11\build\native\include
    

    The first line should be the location where you put glibconfig.h

  • Now in "Linker" add to "Additional dependencies":

    glib-2.0.lib gio-2.0.lib gmodule-2.0.lib gobject-2.0.lib gthread-2.0.lib
    

You should be able to compile now, but the DLLs are still missing from the output folder so you can't run the program.

Step 3 (Copy DLLs)

  • In "Build Events"/"Post-Build Event" set the command line to the following:

    xcopy /y /d "$(SolutionDir)packages\glib.redist.2.36.2.11\build\native\bin\v110\$(Platform)\$(Configuration)\dynamic\*.dll" "$(OutDir)"
    xcopy /y /d "$(SolutionDir)packages\libintl.redist.0.18.2.10\build\native\bin\v110\$(Platform)\$(Configuration)\dynamic\cdecl\*.dll" "$(OutDir)"
    

Now you should be able to run your program without manually compiling glib.

Upvotes: 4

Related Questions