Menu

Issue with using dlib/threads

Help
2014-06-24
2015-04-21
  • Gregory Sharp

    Gregory Sharp - 2014-06-24

    Hi, I thought to try out dlib's thread wrapper. I created a program like below:

    #include "dlib/threads.h"
    int main () {
    return 0; 
    }
    

    This gives me the below error. Any idea what is happening? This is dlib 18.7 with MSVC 9.

    Thanks!
    Greg

    1>dlib_thread_test.obj : error LNK2019: unresolved external symbol _USER_ERRORviolation_of_one_definition_rule_detectedinconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives referenced in function _dlib_check_consistent_assert_usage
    1>C:\gcs6\build\vs2008\plastimatch-3.20.1-dcmtk\Release\dlib_thread_test.exe : fatal error LNK1120: 1 unresolved externals

     

    Last edit: Gregory Sharp 2014-06-24
    • Davis

      Davis - 2014-06-24

      You probably forgot to add dlib/all/source.cpp into your application.

      Cheers,
      Davis

       
  • Gregory Sharp

    Gregory Sharp - 2014-06-24

    Just figured that out! I'm so used to using dlib as header only. Thanks Davis!

     
    • Davis

      Davis - 2014-06-24

      No problem :)

      Cheers,
      Davis

       
  • Gregory Sharp

    Gregory Sharp - 2014-06-24

    Just figured that out! I'm so used to using dlib as header only. Thanks Davis!

     
  • Gregory Sharp

    Gregory Sharp - 2014-06-25

    I still have a problem with this. It seems that I will need to replicate the code within each DLL that uses it. Or else, if I want to centralize the dlib functions within a single DLL, I should write my own wrapper functions (with my own header files that don't include dlib header files) which call the dlib functions. Otherwise, I get the same link error.

    Also, the dlib don't look like they respect declspec decorations, no?

     
    • Davis

      Davis - 2014-06-25

      I would recommend statically compiling dlib into your dlls.

      Right, I haven't put any declspec annotations anywhere in dlib and in
      general making shared libraries from C++ code is quite problematic.
      Especially with visual studio and it's various different runtimes. See
      also http://dlib.net/howto_contribute.html#9.

      So I would really just statically compile it in. If you really care
      about binary size you can include the individual cpp files from dlib
      (rather than dlib/all/source.cpp which includes everything) and that
      will cut down on the size.

      Cheers,
      Davis

       
  • Gregory Sharp

    Gregory Sharp - 2014-06-25

    OK, I understand. Thanks!

     
    • Davis

      Davis - 2014-06-25

      No problem :)

       
  • Samuel

    Samuel - 2014-11-07

    Hi, i’m having a similar issue with svm_threaded but adding dlib/all/source.cpp to my project source files results in lots of linker errors (this happen with mingw). But on visual studio it doesn't change anything, though I won't say I totally understand what you mean by adding the source.cpp to my application, please I'll need your help in this regard.

     
    • Davis

      Davis - 2014-11-07

      How exactly are you compiling it and what are the errors?

      Cheers,
      Davis

       
  • kHenry

    kHenry - 2015-04-21

    I have a similar problem. I'm using dlib with my dll library. Specifically, the dlib is static library and the dlib is linked with my dll library. I just want to link my dll library when I want to use dlib. So, I made new project and I linked my dll library which has static dlib. But it made an error like this:

    unresolved external symbol USER_ERRORmissing_dlib_all_source_cpp_fileOR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_

    can I fix this error?

     
    • Davis

      Davis - 2015-04-21

      It means you aren't consistently #defining DEBUG or ENABLE_ASSERTS in your
      code. Some .cpp files are compiled with one or both of those preprocessor
      macros defined while others are not, resulting in a violation of C++'s one
      definition rule (see http://en.wikipedia.org/wiki/One_Definition_Rule).
      Moreover, you should probably read this article that talks about the
      difficulties of using C++ inside dlls:
      http://siomsystems.com/mixing-visual-studio-versions/. The short summary
      is don't use dlls.

       
  • Chaithra Kumari

    Chaithra Kumari - 2017-02-08

    Hi,

    I am working on dlib from past 2 weeks.I want to step into cpp file of function (Means I want to see the source code) as i was doing in opencv.Can you please help me to find?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.