Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creator builds acting oddly...

Creator builds acting oddly...

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 601 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
    #1

    ...not sure how to put this into words, so I'll just show you the files and the result:

    main.cpp:

    #include "testsha.h"
    int main()
    {
        SHA256Reset();
        return 0;
    }
    

    testsha.h:

    extern int SHA256Reset();
    

    testsha224-256.cpp:

    int SHA256Reset()
    {
      return 0;
    }
    

    When I build, I get this error:

    C:\Users\MZimmers\Qt projects\test\main.cpp:5: error: undefined reference to `SHA256Reset()'
    

    When I change the file testsha224-256.c to a .cpp file, do a clean, a qmake and a build, the error goes away.

    Can someone explain this behavior to me?

    Windows 10, newest version of Creator, MinGW 5.3.0.

    Thanks...this one has me cross-eyed.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      this is not a issue with qt build i feel. it issue with mixing c and cpp in same project.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

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

        Right you are. After sleeping on it, I did some googling and realized that the inclusion of the header file needs to be enclosed thusly:

        extern "C"
        {
        #include testsha.h
        }
        

        (There are other ways of doing this, but this is cleanest for a C header file you don't wish to edit.)

        This prevents the C++ compiler from altering (some say "mangling") the function name.

        Thanks for looking.

        1 Reply Last reply
        0

        • Login

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