Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. compiler error on inclusion of string library

compiler error on inclusion of string library

Scheduled Pinned Locked Moved Solved C++ Gurus
4 Posts 3 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #1

    Hi all -

    When I use a "#include <string>" in a header file, I get the following compiler errors:

    In file included from c:\msys32\opt\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0\bits\stringfwd.h:40:0,
                     from c:\msys32\opt\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0\string:39,
                     from C:/esp32_projects/wifibutton/main/message.h:5,
                     from C:/esp32_projects/wifibutton/main/wifi_esp32.h:8,
                     from C:/esp32_projects/wifibutton/main/main.cpp:17:
    c:\msys32\opt\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0\bits\memoryfwd.h:63:3: error: template with C linkage
       template<typename>
       ^
    c:\msys32\opt\xtensa-esp32-elf\xtensa-esp32-elf\include\c++\5.2.0\bits\memoryfwd.h:66:3: error: template specialization with C linkage
       template<>
       ^
    

    The more I experiment with this, it seems the more confused I get. What am I doing wrong?

    Thanks...

    EDIT: fixed by eliminating unnecessary use of extern "C" declarations. Appropriate for main function, but not class definitions.

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      When mixing C and C++, you usually need to wrap them like:

      #ifdef __cplusplus
      extern "C" {
      #endif
      
      /// Your stuff
      
      #ifdef __cplusplus
      }  //extern "C"
      #endif
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        Yes, and therein lies the dilemma - the extern "C" turns off the function decoration that template function names require. I'd gone through and used extern "C" on all my classes, and that got me into trouble. Took me a while to discover the problem. The solution is a combination of parsimonious usage of the extern "C" along with thorough planning for use of the STL within the application.

        Unfortunately, I had done neither.

        JKSHJ 1 Reply Last reply
        0
        • mzimmersM mzimmers

          Yes, and therein lies the dilemma - the extern "C" turns off the function decoration that template function names require. I'd gone through and used extern "C" on all my classes, and that got me into trouble. Took me a while to discover the problem. The solution is a combination of parsimonious usage of the extern "C" along with thorough planning for use of the STL within the application.

          Unfortunately, I had done neither.

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @mzimmers said in compiler error on inclusion of string library:

          Yes, and therein lies the dilemma - the extern "C" turns off the function decoration that template function names require. I'd gone through and used extern "C" on all my classes, and that got me into trouble.

          That's because C does not support templates (or classes!). The API wrapped in extern "C" must be C-compatible.

          There is a way (I'd call it a hack) to add member functions to extern "C" structs though: https://stackoverflow.com/a/1950150/1144539

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved