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. Newbie question - using C
QtWS25 Last Chance

Newbie question - using C

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 4 Posters 4.3k 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.
  • A Offline
    A Offline
    aethelnorn
    wrote on last edited by
    #8

    OK, thnks, that sounds about right. This is what I have:
    alt text

    the errors include:

    /Users/phill/dev/SmugglerMac/SmugglerMac/core/smuggler/smugbase.h:14: error: 'jinclude.h' file not found
    #include "jinclude.h"
    ^~~~~~~~~~~~

    I am happy to remove the files from the tree (if I knew how) and add them directly to the project, but I am also happy for them to stay where they are too.

    Where do I set HEADERS?

    mrjjM 1 Reply Last reply
    0
    • A aethelnorn

      OK, thnks, that sounds about right. This is what I have:
      alt text

      the errors include:

      /Users/phill/dev/SmugglerMac/SmugglerMac/core/smuggler/smugbase.h:14: error: 'jinclude.h' file not found
      #include "jinclude.h"
      ^~~~~~~~~~~~

      I am happy to remove the files from the tree (if I knew how) and add them directly to the project, but I am also happy for them to stay where they are too.

      Where do I set HEADERS?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #9

      @aethelnorn
      Hi
      In that case
      http://doc.qt.io/qt-5/qmake-variable-reference.html#headers
      INCLUDEPATH
      is the one you are after.
      You add it to the .pro file.
      Make sure to run qmake in menu after.
      you can use absolute paths or relatives.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        aethelnorn
        wrote on last edited by
        #10

        Thanks, that helps some.

        That .pro file is the centre of things isnt it?. I can add and remove files in there manually? As long as I run QMake after?

        I added:

        INCLUDEPATH = ../../../../../SmugglerMac/SmugglerMac/core/libjpeg ../../../../../SmugglerMac/SmugglerMac/core/smuggler/aes ../../../../../SmugglerMac/SmugglerMac/core/smuggler

        and now get :

        -1: error: symbol(s) not found for architecture x86_64
        :-1: error: linker command failed with exit code 1 (use -v to see invocation)

        I am building desktop Qt 5.12.0 clang 64bit

        should I have appended to the existing INCLUDEPATH somehow rather than declaring it as I did?

        mrjjM 1 Reply Last reply
        0
        • A aethelnorn

          Thanks, that helps some.

          That .pro file is the centre of things isnt it?. I can add and remove files in there manually? As long as I run QMake after?

          I added:

          INCLUDEPATH = ../../../../../SmugglerMac/SmugglerMac/core/libjpeg ../../../../../SmugglerMac/SmugglerMac/core/smuggler/aes ../../../../../SmugglerMac/SmugglerMac/core/smuggler

          and now get :

          -1: error: symbol(s) not found for architecture x86_64
          :-1: error: linker command failed with exit code 1 (use -v to see invocation)

          I am building desktop Qt 5.12.0 clang 64bit

          should I have appended to the existing INCLUDEPATH somehow rather than declaring it as I did?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #11

          @aethelnorn
          Hi
          Yes you can edit .pro file manually all you want. Its the project file and
          defines how to build a project.
          if you have an existing INCLUDEPATH
          then please do
          INCLUDEPATH += ../xxxxxx
          so you dont override the already set values.

          A 1 Reply Last reply
          3
          • mrjjM mrjj

            @aethelnorn
            Hi
            Yes you can edit .pro file manually all you want. Its the project file and
            defines how to build a project.
            if you have an existing INCLUDEPATH
            then please do
            INCLUDEPATH += ../xxxxxx
            so you dont override the already set values.

            A Offline
            A Offline
            aethelnorn
            wrote on last edited by
            #12

            @mrjj I tried the += but it made no difference.

            I deleted all my 'extra' files from .pro, and it all compiles and runs again.

            So something in my C files is interfering with the make to give the linker error. That is me flummoxed, as most of the files are open source and so I do not want to modify them (even if I did understand them). It would be a shame if the project failed at this point, because I am impressed with what I have seen of Qt so far.

            The only thing that I can imagine is that one of the component projects is jpeg-9c which had a qmake system of its own, and may have generated some of the header files in a way that confuses qmake in Qt? I can drop the exact same set of files into XCode swift project and they compile a treat (iOS or MacOS). I have also compiled them inside android studio and accessed them through JNI.

            mrjjM 1 Reply Last reply
            0
            • A aethelnorn

              @mrjj I tried the += but it made no difference.

              I deleted all my 'extra' files from .pro, and it all compiles and runs again.

              So something in my C files is interfering with the make to give the linker error. That is me flummoxed, as most of the files are open source and so I do not want to modify them (even if I did understand them). It would be a shame if the project failed at this point, because I am impressed with what I have seen of Qt so far.

              The only thing that I can imagine is that one of the component projects is jpeg-9c which had a qmake system of its own, and may have generated some of the header files in a way that confuses qmake in Qt? I can drop the exact same set of files into XCode swift project and they compile a treat (iOS or MacOS). I have also compiled them inside android studio and accessed them through JNI.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #13

              @aethelnorn
              well did you include more than .h and .c files ?
              Like dylib file or someting like that ?
              If all the c files compiles its a good sign.

              A 1 Reply Last reply
              0
              • mrjjM mrjj

                @aethelnorn
                well did you include more than .h and .c files ?
                Like dylib file or someting like that ?
                If all the c files compiles its a good sign.

                A Offline
                A Offline
                aethelnorn
                wrote on last edited by
                #14

                @mrjj Nothing but .c and .h added, I used grep and none of the files contained the text "x86_64"

                mrjjM 1 Reply Last reply
                0
                • A aethelnorn

                  @mrjj Nothing but .c and .h added, I used grep and none of the files contained the text "x86_64"

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #15

                  @aethelnorn
                  Ok, can you check the output pane to find out what exactly fails ?
                  like here
                  https://stackoverflow.com/questions/18973042/symbols-not-found-for-architecture-x86-64-on-qtcreator-project

                  1 Reply Last reply
                  2
                  • A Offline
                    A Offline
                    aethelnorn
                    wrote on last edited by
                    #16

                    @mrjj But yes, compile is a big step forward.

                    I have looked at the stackOverflow article, and I think you are onto something there a symbol (an array) is not being found. However the array is #defined to something else (in a #ifdef and I do not know if that evaluates true at that point). Lots of other breaks in that file which makes me surprised that it compiles. Maybe the compile fails do not prevent linking as here are lots of platform-alternates here.

                    jpeg-9c has a lot of macros etc to allow multiplatform and it looks as if the Qt build system is choking on them. So am I to be honest - too many levels of indirection spread across too many files.

                    I need to break off for now, but I will be back tomorrow after a rest. Maybe I will gain some more clarity with a new look in the morning. Thanks for your help so far - it is much appreciated.

                    mrjjM aha_1980A 2 Replies Last reply
                    1
                    • A aethelnorn

                      @mrjj But yes, compile is a big step forward.

                      I have looked at the stackOverflow article, and I think you are onto something there a symbol (an array) is not being found. However the array is #defined to something else (in a #ifdef and I do not know if that evaluates true at that point). Lots of other breaks in that file which makes me surprised that it compiles. Maybe the compile fails do not prevent linking as here are lots of platform-alternates here.

                      jpeg-9c has a lot of macros etc to allow multiplatform and it looks as if the Qt build system is choking on them. So am I to be honest - too many levels of indirection spread across too many files.

                      I need to break off for now, but I will be back tomorrow after a rest. Maybe I will gain some more clarity with a new look in the morning. Thanks for your help so far - it is much appreciated.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #17

                      @aethelnorn
                      the c code might have some
                      ifdef
                      ..code..
                      endif
                      that should be defined for it to link.
                      Note that Creator should show if a define is enabled

                      alt text

                      A 1 Reply Last reply
                      3
                      • A aethelnorn

                        @mrjj But yes, compile is a big step forward.

                        I have looked at the stackOverflow article, and I think you are onto something there a symbol (an array) is not being found. However the array is #defined to something else (in a #ifdef and I do not know if that evaluates true at that point). Lots of other breaks in that file which makes me surprised that it compiles. Maybe the compile fails do not prevent linking as here are lots of platform-alternates here.

                        jpeg-9c has a lot of macros etc to allow multiplatform and it looks as if the Qt build system is choking on them. So am I to be honest - too many levels of indirection spread across too many files.

                        I need to break off for now, but I will be back tomorrow after a rest. Maybe I will gain some more clarity with a new look in the morning. Thanks for your help so far - it is much appreciated.

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

                        @aethelnorn while it in principle possible to compile everything with qmake, the question arises if the external libs should be build with their 'native' buildsystem and just be linked into your project.

                        At least thats the way most projects handle it, an thats also cleanest regarding licenses (GPL e.g.)

                        Qt has to stay free or it will die.

                        A 1 Reply Last reply
                        3
                        • mrjjM mrjj

                          @aethelnorn
                          the c code might have some
                          ifdef
                          ..code..
                          endif
                          that should be defined for it to link.
                          Note that Creator should show if a define is enabled

                          alt text

                          A Offline
                          A Offline
                          aethelnorn
                          wrote on last edited by
                          #19

                          @mrjj That is a handy tip - it is 20 years since I coded C/C++ I have been spoiled by Java. Any help from the tools is more than welcome.

                          1 Reply Last reply
                          0
                          • aha_1980A aha_1980

                            @aethelnorn while it in principle possible to compile everything with qmake, the question arises if the external libs should be build with their 'native' buildsystem and just be linked into your project.

                            At least thats the way most projects handle it, an thats also cleanest regarding licenses (GPL e.g.)

                            A Offline
                            A Offline
                            aethelnorn
                            wrote on last edited by
                            #20

                            @aha_1980 I can see where you are coming from, but to compile the library first I have to install and understand all the cross-platform compiling technology. This is not something that attracts me. I was hoping that I could delegate that work to Qt. If I need to precompile the libraries then I have two projects (Qt and cross compile system) instead of one. That is very little improvement over my current solution (Xcode & Android projects) and requires extra learning.

                            If I can convert an automake project into a Qt project that might help - jpeg-9c is set up for automake. Two Qt projects would be an attractive solution. As this is a private project I will need to wait until this evening to give it some more time.

                            As for licensing, both the open source projects I use are very permissive, and the resultant code when finished will be open-sourced (GPL3 most likely if Qt is part of the solution).

                            aha_1980A 1 Reply Last reply
                            0
                            • A aethelnorn

                              @aha_1980 I can see where you are coming from, but to compile the library first I have to install and understand all the cross-platform compiling technology. This is not something that attracts me. I was hoping that I could delegate that work to Qt. If I need to precompile the libraries then I have two projects (Qt and cross compile system) instead of one. That is very little improvement over my current solution (Xcode & Android projects) and requires extra learning.

                              If I can convert an automake project into a Qt project that might help - jpeg-9c is set up for automake. Two Qt projects would be an attractive solution. As this is a private project I will need to wait until this evening to give it some more time.

                              As for licensing, both the open source projects I use are very permissive, and the resultant code when finished will be open-sourced (GPL3 most likely if Qt is part of the solution).

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

                              @aethelnorn said in Newbie question - using C:

                              If I can convert an automake project into a Qt project that might help - jpeg-9c is set up for automake

                              Yes, you can do that - I did the same with net-snmp some weeks ago. I have to say it took me 1-2 days to do so, because I throw away automake and therefore had to do all the platform decisions to set defines and compile/exclude C files myself. Advantage is now, that I can cross-compile for ARM immediately - it seems you aim for the same.

                              I would really recommend you to separate these libraries from your own project, i.e. create separate .pro files for them.

                              Afterwards you can glue all together with a top-level SUBDIRs pro file.

                              Regards

                              Qt has to stay free or it will die.

                              A 1 Reply Last reply
                              3
                              • aha_1980A aha_1980

                                @aethelnorn said in Newbie question - using C:

                                If I can convert an automake project into a Qt project that might help - jpeg-9c is set up for automake

                                Yes, you can do that - I did the same with net-snmp some weeks ago. I have to say it took me 1-2 days to do so, because I throw away automake and therefore had to do all the platform decisions to set defines and compile/exclude C files myself. Advantage is now, that I can cross-compile for ARM immediately - it seems you aim for the same.

                                I would really recommend you to separate these libraries from your own project, i.e. create separate .pro files for them.

                                Afterwards you can glue all together with a top-level SUBDIRs pro file.

                                Regards

                                A Offline
                                A Offline
                                aethelnorn
                                wrote on last edited by
                                #22

                                @aha_1980 That sounds like a very promising approach. Where would I find some literature on how to convert an automake project into a .pro project. Assume my skill level is 'inexperienced'. The jpeg-9c library needs to be converted. The TinyAES library is just one C and one H file, so is likely not worth converting.

                                aha_1980A 1 Reply Last reply
                                0
                                • A aethelnorn

                                  @aha_1980 That sounds like a very promising approach. Where would I find some literature on how to convert an automake project into a .pro project. Assume my skill level is 'inexperienced'. The jpeg-9c library needs to be converted. The TinyAES library is just one C and one H file, so is likely not worth converting.

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

                                  @aethelnorn

                                  Unfortunately, I'm not aware of some conversion step-by-step tutorial...

                                  Assume my skill level is 'inexperienced'.

                                  That is not the best start point, but if you are willing to learn still manageable. You'll have a better understanding of the qmake build process afterwards.

                                  The jpeg-9c library needs to be converted.

                                  I'd start with building the library on your host system with the usual way, probably

                                  ./configure --your-wanted-options-here
                                  make
                                  

                                  You should carefully watch the build log and note the compiler switches and defines passed to the source files. You will later need to pass them from qmake.

                                  Then set up a new qmake project (best in a separate folder) by qmake -project. That will fill the SOURCES and HEADERS field in the pro file for you. You may need to change TEMPLATE=lib and then add QMAKE_CFLAGS as well as DEFINES to imitate the original build.

                                  Start with the small library to gain some experience, then try the bigger one.

                                  Good luck!

                                  Qt has to stay free or it will die.

                                  A 2 Replies Last reply
                                  4
                                  • aha_1980A aha_1980

                                    @aethelnorn

                                    Unfortunately, I'm not aware of some conversion step-by-step tutorial...

                                    Assume my skill level is 'inexperienced'.

                                    That is not the best start point, but if you are willing to learn still manageable. You'll have a better understanding of the qmake build process afterwards.

                                    The jpeg-9c library needs to be converted.

                                    I'd start with building the library on your host system with the usual way, probably

                                    ./configure --your-wanted-options-here
                                    make
                                    

                                    You should carefully watch the build log and note the compiler switches and defines passed to the source files. You will later need to pass them from qmake.

                                    Then set up a new qmake project (best in a separate folder) by qmake -project. That will fill the SOURCES and HEADERS field in the pro file for you. You may need to change TEMPLATE=lib and then add QMAKE_CFLAGS as well as DEFINES to imitate the original build.

                                    Start with the small library to gain some experience, then try the bigger one.

                                    Good luck!

                                    A Offline
                                    A Offline
                                    aethelnorn
                                    wrote on last edited by
                                    #24

                                    @aha_1980 said in Newbie question - using C:

                                    @aethelnorn

                                    Unfortunately, I'm not aware of some conversion step-by-step tutorial...

                                    Assume my skill level is 'inexperienced'.

                                    That is not the best start point, but if you are willing to learn still manageable. You'll have a better understanding of the qmake build process afterwards.

                                    But it is the best starting point for learning something new. Easier to fill an empty cup..... I am not afraid of learning new stuff - I am in my fifth decade of coding, still learning stuff just getting slower.

                                    The jpeg-9c library needs to be converted.

                                    I'd start with building the library on your host system with the usual way, probably

                                    ./configure --your-wanted-options-here
                                    make
                                    

                                    You should carefully watch the build log and note the compiler switches and defines passed to the source files. You will later need to pass them from qmake.

                                    Then set up a new qmake project (best in a separate folder) by qmake -project. That will fill the SOURCES and HEADERS field in the pro file for you. You may need to change TEMPLATE=lib and then add QMAKE_CFLAGS as well as DEFINES to imitate the original build.

                                    Sounds feasible. I will have to tease out several features - jpeg-9c contains both library and command line utility source in one dir/make system, and I only want the library. Still it is a promising way forward.

                                    Start with the small library to gain some experience, then try the bigger one.

                                    Smaller library is not automake, just make - so likely will be misleadingly simple. But it will introduce me to creating a .pro library

                                    Good luck!

                                    Thanks, and thank you for your help (and the others on this thread). I will give this a try over the weekend and report back.

                                    Aethelnorn

                                    1 Reply Last reply
                                    2
                                    • aha_1980A aha_1980

                                      @aethelnorn

                                      Unfortunately, I'm not aware of some conversion step-by-step tutorial...

                                      Assume my skill level is 'inexperienced'.

                                      That is not the best start point, but if you are willing to learn still manageable. You'll have a better understanding of the qmake build process afterwards.

                                      The jpeg-9c library needs to be converted.

                                      I'd start with building the library on your host system with the usual way, probably

                                      ./configure --your-wanted-options-here
                                      make
                                      

                                      You should carefully watch the build log and note the compiler switches and defines passed to the source files. You will later need to pass them from qmake.

                                      Then set up a new qmake project (best in a separate folder) by qmake -project. That will fill the SOURCES and HEADERS field in the pro file for you. You may need to change TEMPLATE=lib and then add QMAKE_CFLAGS as well as DEFINES to imitate the original build.

                                      Start with the small library to gain some experience, then try the bigger one.

                                      Good luck!

                                      A Offline
                                      A Offline
                                      aethelnorn
                                      wrote on last edited by
                                      #25

                                      @aha_1980 Ok, I have done this:

                                      • run configure with the option set to create a static library only.
                                      • run make, but I could not find a log (do I need options to produce one?) all I saw was a bunch of 'CC this' and 'CCLD that' commands
                                      • I copied the .H and .C files I need for jpeglib to a separate folder and ran '~/dev/Qt/5.12.0/clang_64/bin/qmake -project' in it.
                                      • Changed TEMPLATE=lib

                                      When I try to 'run' or 'release' (or whatever it is the'play' button is doing) I get a prompt for 'which app to run' (I cancel at this point). Can I assume that the compile and link of the library is happy (I can see warnings but no errors in the compile output window). If I have been successful, then where is my lib? I would like to see it to believe it......

                                      The last lines in the compile output window are:

                                      rm -f liblibjpeg.1.0.0.dylib liblibjpeg.dylib liblibjpeg.1.dylib liblibjpeg.1.0.dylib
                                      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -stdlib=libc++ -headerpad_max_install_names -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.12 -Wl,-rpath,@executable_path/Frameworks -Wl,-rpath,/Users/phill/dev/Qt/5.12.0/clang_64/lib -single_module -dynamiclib -compatibility_version 1.0 -current_version 1.0.0 -install_name liblibjpeg.1.dylib -o liblibjpeg.1.0.0.dylib jaricom.o jcapimin.o jcapistd.o jcarith.o jccoefct.o jccolor.o jcdctmgr.o jchuff.o jcinit.o jcmainct.o jcmarker.o jcmaster.o jcomapi.o jcparam.o jcprepct.o jcsample.o jctrans.o jdapimin.o jdapistd.o jdarith.o jdatadst.o jdatasrc.o jdcoefct.o jdcolor.o jddctmgr.o jdhuff.o jdinput.o jdmainct.o jdmarker.o jdmaster.o jdmerge.o jdpostct.o jdsample.o jdtrans.o jerror.o jfdctflt.o jfdctfst.o jfdctint.o jidctflt.o jidctfst.o jidctint.o jmemmgr.o jmemnobs.o jquant1.o jquant2.o jutils.o -F/Users/phill/dev/Qt/5.12.0/clang_64/lib -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL
                                      ln -s liblibjpeg.1.0.0.dylib liblibjpeg.dylib
                                      ln -s liblibjpeg.1.0.0.dylib liblibjpeg.1.dylib
                                      ln -s liblibjpeg.1.0.0.dylib liblibjpeg.1.0.dylib
                                      19:35:40: The process "/usr/bin/make" exited normally.
                                      19:35:40: Elapsed time: 00:02.

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        aethelnorn
                                        wrote on last edited by
                                        #26

                                        Whoops, ignore that last comment - I have found my libs (I was looking in the wrong directory - an earlier attempt). But they have become named liblibjpeg.dylib etc. Can I simplify the name?

                                        And can you point me to a resource which describes how to make a project using this static lib project. If it were gradle it would be called a 'multiproject'.

                                        So thanks to your help I could be on my way here.

                                        Aethelnorn

                                        aha_1980A 1 Reply Last reply
                                        0
                                        • A aethelnorn

                                          Whoops, ignore that last comment - I have found my libs (I was looking in the wrong directory - an earlier attempt). But they have become named liblibjpeg.dylib etc. Can I simplify the name?

                                          And can you point me to a resource which describes how to make a project using this static lib project. If it were gradle it would be called a 'multiproject'.

                                          So thanks to your help I could be on my way here.

                                          Aethelnorn

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

                                          @aethelnorn said in Newbie question - using C:

                                          Whoops, ignore that last comment - I have found my libs (I was looking in the wrong directory - an earlier attempt). But they have become named liblibjpeg.dylib etc. Can I simplify the name?

                                          Sure. How do you name them in the TARGET line? Just remove the leading "lib" there, it is added automatically (a "convention" for early UNIX times).

                                          And can you point me to a resource which describes how to make a project using this static lib project. If it were gradle it would be called a 'multiproject'.

                                          As said before, the search term is SUBDIRS, e.g.:

                                          • https://stackoverflow.com/questions/1417776/how-to-use-qmakes-subdirs-template
                                          • https://wiki.qt.io/SUBDIRS_-_handling_dependencies

                                          and - IMPORTANT -

                                          • https://blog.rburchell.com/2013/10/every-time-you-configordered-kitten-dies.html

                                          might help you in that regard.

                                          Qt has to stay free or it will die.

                                          A 1 Reply Last reply
                                          3

                                          • Login

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