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. Building a c shared library in QtCreator
Forum Updated to NodeBB v4.3 + New Features

Building a c shared library in QtCreator

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 614 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.
  • M Offline
    M Offline
    Martyn
    wrote on last edited by
    #1

    Hi all,

    I have a project that needs to build a DSO with few dependencies and an initialisation function. I'm using QtCreator and qmake.

    In the .pro file created I have

    TEMPLATE = lib
    

    There is only a single c source file.

    It builds the DSO using the c++ compiler . The question is how do I instruct it to use c to link the DSO, and secondly how do I pass additional arguments. I was trying

    LINK = cc
    LFLAGS += -Wl,-init,MyInit
    

    But neither seem to have an effect....

    jsulmJ 1 Reply Last reply
    0
    • M Martyn

      Hi all,

      I have a project that needs to build a DSO with few dependencies and an initialisation function. I'm using QtCreator and qmake.

      In the .pro file created I have

      TEMPLATE = lib
      

      There is only a single c source file.

      It builds the DSO using the c++ compiler . The question is how do I instruct it to use c to link the DSO, and secondly how do I pass additional arguments. I was trying

      LINK = cc
      LFLAGS += -Wl,-init,MyInit
      

      But neither seem to have an effect....

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @martyn What is the file name extension of you C file? Is it .cpp or .c?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Martyn
        wrote on last edited by
        #3

        Its ".c" ...

        Martyn

        G 1 Reply Last reply
        0
        • M Martyn

          Its ".c" ...

          Martyn

          G Offline
          G Offline
          Gerd
          wrote on last edited by
          #4

          @martyn
          shouldn't that be

          QMAKE_LINK = cc
          QMKAE_LFLAGS+= -Wl,-init,MyInit
          
          

          ?

          aha_1980A 1 Reply Last reply
          1
          • G Gerd

            @martyn
            shouldn't that be

            QMAKE_LINK = cc
            QMKAE_LFLAGS+= -Wl,-init,MyInit
            
            

            ?

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @gerd is correct. The question to @Martyn is rather, why is QMAKE_LINK needed?

            The question is how do I instruct it to use c to link the DSO

            There is no such thing as a C or C++ linker. The linker links just symbols. If your file is compiled with a C++ compiler, then something wents wrong.

            Please post the whole .pro file and the complete compile log for reference.

            Qt has to stay free or it will die.

            M 1 Reply Last reply
            2
            • aha_1980A aha_1980

              @gerd is correct. The question to @Martyn is rather, why is QMAKE_LINK needed?

              The question is how do I instruct it to use c to link the DSO

              There is no such thing as a C or C++ linker. The linker links just symbols. If your file is compiled with a C++ compiler, then something wents wrong.

              Please post the whole .pro file and the complete compile log for reference.

              M Offline
              M Offline
              Martyn
              wrote on last edited by
              #6

              @gerd said in Building a c shared library in QtCreator:

              @martyn
              shouldn't that be

              QMAKE_LINK = cc
              QMKAE_LFLAGS+= -Wl,-init,MyInit
              

              OK - Yes the QMAKE_ versions do work :-)

              @aha_1980 said in Building a c shared library in QtCreator:

              @gerd is correct. The question to @Martyn is rather, why is QMAKE_LINK needed?

              The question is how do I instruct it to use c to link the DSO

              There is no such thing as a C or C++ linker. The linker links just symbols. If your file is compiled with a C++ compiler, then something wents wrong.

              Yes - I am wanting to use gcc as the (frontend/driver for the) linker to avoid libstdc++ being linked. To confirm, the source file was always being compiled by the c compiler.

              Please post the whole .pro file and the complete compile log for reference.

              QT       -= core gui
              TARGET = myproject
              TEMPLATE = lib
              DEFINES += MYPROJECT_LIBRARY
              DEFINES += QT_DEPRECATED_WARNINGS
              QMAKE_LFLAGS += -Wl,-init,myprojectInit
              #QMAKE_LINK = cc
              
              SOURCES += \
                      binding.c
              
              HEADERS += \
                      binding.h \
                      pebinder_global.h 
              
              unix {
                  target.path = /usr/lib
                  INSTALLS += target
              }
              

              This provides the link step as

              g++ -Wl,-init,myprojectInit -Wl,-O1 -Wl,-z,relro -shared -Wl,-soname,libmyproject.so.1 -o libmyproject.so.1.0.0 binding.o -lpthread
              

              So, as you say, the question is should qmake be smart enough to realise that c++ isn't needed to link if all the source files are .c.

              Though I'm happy to now have a simple solution :-)

              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