Results 1 to 15 of 15

Thread: The linker appears not to be linking.

  1. #1
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default The linker appears not to be linking.

    I'm using QT 4.7.3 with the MSVC 9.0 compiler.
    I'm trying to link to a lib in a separate VS2010 project.

    The code compiles just fine, but I keep getting "unresolved external symbol" errors. (So far I'm only attempting to call the constructor of object I need to link to, nothing complicated).

    I tried the following methods of linking in my .pro file:

    Qt Code:
    1. LIBS += -L\\C:\\PathToLib -lLibname
    2. LIBS += -L\\C:\\PathToLib\\Libname.lib
    3. LIBS += C:\\PathToLib\\Libname.lib
    4. LIBS += Libname.lib #I copied the lib to the current directory
    To copy to clipboard, switch view to plain text mode 

    I'm not getting any errors saying that it can't find the library, only that it can't find the symbols in it. It almost seems like the linker is just completely ignoring it.

    I thought that there may have been a problem with differences between MSVC 9.0 and MSVC 10.0, so I changed all the settings in QT to use 10.0 (to match the VS project I'm trying to link to), but absolutely nothing changed.


    Is there anything else I can try, or any reason the linker might be ignoring my lib?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: The linker appears not to be linking.

    Its not enough to change the pro file when using MSVS. (visual studio is not readin the pro file at all, it will generate one based on its own project settings though, or read a pro file and generate its own properties out of it)
    You have to specify the lib path and lib in the project settings in MSVS.
    Last edited by high_flyer; 15th September 2011 at 11:02.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: The linker appears not to be linking.

    @high_flyer : I dont agree with that, if you re-run qmake on the pro file it should be enough to build the corresponding .vcproj files. At least i never edit MSVS settings directly.

    orfner, do you link dynamically or staticly ? If you chose the dynamic way, does your class exports its symbols ?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: The linker appears not to be linking.

    if you re-run qmake on the pro file it should be enough to build the corresponding .vcproj files.
    With out telling MSVS to re-read the pro file?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: The linker appears not to be linking.

    Sorry we are a little bit off-topic here.. What I meant by "re-run qmake on the pro file" is the following :
    Qt Code:
    1. qmake -tp vc -recursive myproj.pro
    To copy to clipboard, switch view to plain text mode 
    This will regenerate vcproj file(s), and if MSVS is running it will detect the change and reload project. Whatever, as I said I never edit project settings through MSVS, and it's not the point here (unless orfner forgot to re-run qmake)

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: The linker appears not to be linking.

    unless orfner forgot to re-run qmake
    That was my point...
    The pro file and vcproj file are not "connected".
    If you change one, you have to update the other.
    But as long as you are working on MSVS, it makes sense to change the pro file, only at the end, when you know your project settings don't change any more - and not change the por file, and update the vcproj every time you do...
    but that is of course a subjective preference issue, each to his own.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: The linker appears not to be linking.

    I knew we were talking about the same thing. I see your point now.

  8. #8
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The linker appears not to be linking.

    Quote Originally Posted by totem View Post
    @high_flyer : I dont agree with that, if you re-run qmake on the pro file it should be enough to build the corresponding .vcproj files. At least i never edit MSVS settings directly.

    orfner, do you link dynamically or staticly ? If you chose the dynamic way, does your class exports its symbols ?

    I'm linking statically.
    I also tried forcing linkage using
    Qt Code:
    1. #pragma comment(lib, "libName.lib")
    To copy to clipboard, switch view to plain text mode 
    in the cpp file that uses the symbols from the libs, but to no avail.

    I should probably clarify, I'm building this from within QT Creator using MSVC, not using the Visual Studio plugin, so there are no .vcproj files generated

    My build arguments are:

    Qt Code:
    1. qmake: qmake.exe ProjectName.pro -r -spec win32-msvc2008 "CONFIG+=release"
    2.  
    3. Make: jom.exe in C:\ProjectPath\ProjectName-build-desktop
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: The linker appears not to be linking.

    You can get rid of these pragma statements as it's compiler-specific and should be replaceable by an appropriate pro file configuration.
    Does your pro file properly define the library libName as statically built ?
    As well, could you provide the linker error messages ?

  10. #10
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: The linker appears not to be linking.

    You said:
    I'm trying to link to a lib in a separate VS2010 project.
    But qmake settings are:
    qmake.exe ProjectName.pro -r -spec win32-msvc2008 "CONFIG+=release"
    Have you tried to change it to use win32-msvc2010 ?

  11. #11
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The linker appears not to be linking.

    Does your pro file properly define the library libName as statically built ?
    Yeah, I'm fairly certain that the way I'm including them in the pro file specifies the libs as static:
    Qt Code:
    1. LIBS += C:/PathToLib/LibName.lib
    To copy to clipboard, switch view to plain text mode 

    Have you tried to change it to use win32-msvc2010 ?
    Yes, and it didn't change anything. I'm currently in the (really long) process of building QT 4.7.4 with MSVC-2010 to see if that makes any difference.

    In other news: I'm not sure what I did, but the linking errors changed...

    Qt Code:
    1. warning LNK4229: invalid directive '/FAILIFMISMATCH:_MSC_VER=1600' encountered; ignored
    2. warning LNK4229: invalid directive '/FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=0' encountered; ignored
    3. warning LNK4229: invalid directive '/FAILIFMISMATCH:_MSC_VER=1600' encountered; ignored
    4. warning LNK4229: invalid directive '/FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=0' encountered; ignored
    5. error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z) referenced in function "public: void __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >::_Xran(void)const " (?_Xran@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEXXZ)
    6. error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
    7. error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
    8. error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
    9. error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z) referenced in function "protected: void __thiscall std::vector<class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >,class std::allocator<class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > > >::_Xlen(void)const "
    10. error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
    11. error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
    12. error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
    13. error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<wchar_t,struct std::char_traits<wchar_t> > & __thiscall std::basic_ostream<wchar_t,struct std::char_traits<wchar_t> >::write(wchar_t const *,__int64)" (__imp_?write@?$basic_ostream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@PB_W_J@Z) referenced in function "public: virtual void __thiscall pugi::xml_writer_stream::write(void const *,unsigned int)" (?write@xml_writer_stream@pugi@@UAEXPBXI@Z)
    14. error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::write(char const *,__int64)" (__imp_?write@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@PBD_J@Z) referenced in function "public: virtual void __thiscall pugi::xml_writer_stream::write(void const *,unsigned int)" (?write@xml_writer_stream@pugi@@UAEXPBXI@Z)
    15. error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_istream<char,struct std::char_traits<char> > & __thiscall std::basic_istream<char,struct std::char_traits<char> >::read(char *,__int64)" (__imp_?read@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@PAD_J@Z) referenced in function "struct pugi::xml_parse_result __cdecl `anonymous namespace'::load_stream_impl<char>(class pugi::xml_document &,class std::basic_istream<char,struct std::char_traits<char> > &,unsigned int,enum pugi::xml_encoding)" (??$load_stream_impl@D@?A0x818da123@@YA?AUxml_parse_result@pugi@@AAVxml_document@2@AAV?$basic_istream@DU?$char_traits@D@std@@@std@@IW4xml_encoding@2@@Z)
    16. error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_istream<char,struct std::char_traits<char> > & __thiscall std::basic_istream<char,struct std::char_traits<char> >::seekg(__int64,int)" (__imp_?seekg@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@_JH@Z) referenced in function "struct pugi::xml_parse_result __cdecl `anonymous namespace'::load_stream_impl<char>(class pugi::xml_document &,class std::basic_istream<char,struct std::char_traits<char> > &,unsigned int,enum pugi::xml_encoding)" (??$load_stream_impl@D@?A0x818da123@@YA?AUxml_parse_result@pugi@@AAVxml_document@2@AAV?$basic_istream@DU?$char_traits@D@std@@@std@@IW4xml_encoding@2@@Z)
    17. error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_istream<wchar_t,struct std::char_traits<wchar_t> > & __thiscall std::basic_istream<wchar_t,struct std::char_traits<wchar_t> >::read(wchar_t *,__int64)" (__imp_?read@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@PA_W_J@Z) referenced in function "struct pugi::xml_parse_result __cdecl `anonymous namespace'::load_stream_impl<wchar_t>(class pugi::xml_document &,class std::basic_istream<wchar_t,struct std::char_traits<wchar_t> > &,unsigned int,enum pugi::xml_encoding)" (??$load_stream_impl@_W@?A0x818da123@@YA?AUxml_parse_result@pugi@@AAVxml_document@2@AAV?$basic_istream@_WU?$char_traits@_W@std@@@std@@IW4xml_encoding@2@@Z)
    18. error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_istream<wchar_t,struct std::char_traits<wchar_t> > & __thiscall std::basic_istream<wchar_t,struct std::char_traits<wchar_t> >::seekg(__int64,int)" (__imp_?seekg@?$basic_istream@_WU?$char_traits@_W@std@@@std@@QAEAAV12@_JH@Z) referenced in function "struct pugi::xml_parse_result __cdecl `anonymous namespace'::load_stream_impl<wchar_t>(class pugi::xml_document &,class std::basic_istream<wchar_t,struct std::char_traits<wchar_t> > &,unsigned int,enum pugi::xml_encoding)" (??$load_stream_impl@_W@?A0x818da123@@YA?AUxml_parse_result@pugi@@AAVxml_document@2@AAV?$basic_istream@_WU?$char_traits@_W@std@@@std@@IW4xml_encoding@2@@Z)
    To copy to clipboard, switch view to plain text mode 

    All of the FAILIFMISMATCH:_MSC_VER=1600 stuff makes me think my problems are in fact coming from different versions of MSVC, even though I changed it to use 2010.

    My conclusion: writing portable software sucks

  12. #12
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: The linker appears not to be linking.

    My conclusion: writing portable software sucks
    Well, you are trying to connect components both compiled with M$ compilers, I wouldn't call that portable :P In your situation I'd rather say: building software with M$ compilers sucks...
    Have you tried to search for the help on some kind of VisualStudio-related forums ?

  13. #13
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The linker appears not to be linking.

    So I changed stuff up a bit, and now I have a much better idea of what's going on.

    I'm implicitly linking by including the header files, referencing the .lib in the pro file, and placing the .dll in the execution folder.

    Right now I'm only using functions from one class from the dll. Some of the functions link, some of them don't. Dependency walker confirms that they're all being exported just fine.

    The functions that don't link take a std::wstring or a std::wstring* as a parameter.

    Both the dll and the qt project use the same compiler (MSVC2010), so it intuitively wouldn't have a problem with basic types...

    Any ideas?

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The linker appears not to be linking.

    Using the same compiler is not enough. As far as I know you can define the width of strings (char vs wchar) for Microsoft compilers using some defines. Maybe you have a mix of that? Have you tried getting rid of Qt code completely and compiling purely C++ code in your project? Of course not one written from scratch but rather using the same libraries and header files.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Apr 2011
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The linker appears not to be linking.

    So for anyone else getting this problem, I just figured it out.

    The linker was breaking because Visual Studio by default maps wchar_t to __wchar_t, and QT does not.

    To fix: Go to Project Settings -> Configuration Properties -> C/C++ -> Language and uncheck the "Treat WChar_t As Built in Type" property.

Similar Threads

  1.  appears in QTextBrowser
    By szisziszilvi in forum Qt Programming
    Replies: 1
    Last Post: 4th March 2011, 08:21
  2. Replies: 4
    Last Post: 14th January 2011, 23:44
  3. QWidget::pos Appears Unreliable
    By mbrusati in forum Qt Programming
    Replies: 1
    Last Post: 25th February 2009, 17:01
  4. QPushButton appears differently
    By gianhut in forum Qt Tools
    Replies: 4
    Last Post: 5th January 2009, 22:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.