Issues compiling c files in Qt creator

Page  
2

December 6, 2010

Volker Volker
Robot Herder
5428 posts

benardmens wrote:

These are some new links which shouldnt give the same problem,

I would appreciate any help as I’ve been trying to get this working for a day now. Thanks again

I put base64.h and and base64.c in a small project and could compile it and use its base64_encode_alloc in a C++ program.

qmake calls g++ or gcc depending on the file extension (cpp or c). I used no pre targets or libs or something like that.

December 6, 2010

maciek maciek
Lab Rat
67 posts

Hi all,
1st thing is that you are not using class. There is no such thing in C as class or object!
Your problem is that you’re using qt tools to compile (.pro file & qmake) which generate Makefiles only for C++. If you want to compile C code with QtCreator you should start using cmake [cmake.org] (which is supported by QtCreator) instead of .pro files.

 Signature 

Earth is a beta site.

December 6, 2010

Volker Volker
Robot Herder
5428 posts

Not quite true.

  1. HEADERS += plain.h base64.h
  2. SOURCES += main.cpp base64.c

This calls g++ (GCC in C++ mode) on main.cpp and gcc (GCC in C mode) on base64.c. The decision is made on the file extension (.cpp or .c). One can tweak that with setting QMAKE_EXT_CPP. The default is .cpp .cc .cxx .C

December 8, 2010

GordonSchumacher GordonSchuma..
Lab Rat
93 posts

Actually, there’s an even better way:

Top-level .pro file:

  1. TEMPLATE = subdirs
  2.  
  3. someLib.subdir = someLib
  4. someLib.makefile = someLib.mak  # This may not be named "Makefile"!
  5. someLib.target = $${QMAKE_PREFIX_SHLIB}someLib.${QMAKE_EXTENSION_SHLIB}
  6.  
  7. SUBDIRS = someLib someApp

someLib/someLib.mak:

  1. libsomeLib.so:
  2.         gcc foo.c -o libsomeLib.so
  3.  
  4. clean:
  5.         rm -f libsomeLib.so
  6.  
  7. distclean: clean
  8.  
  9. .PHONY: clean distclean

Note that it will create a bogus, non-functional “someLib/Makefile”, but you may simply ignore it.

I don’t believe this is documented, but it’s been in qmake for quite a long time (I want to say at least since 4.3.x, but don’t quote me on that).

December 11, 2010

benardmens benardmens
Lab Rat
13 posts

GordonSchumacher wrote:
Actually, there’s an even better way:

Top-level .pro file:

  1. TEMPLATE = subdirs
  2.  
  3. someLib.subdir = someLib
  4. someLib.makefile = someLib.mak  # This may not be named "Makefile"!
  5. someLib.target = $${QMAKE_PREFIX_SHLIB}someLib.${QMAKE_EXTENSION_SHLIB}
  6.  
  7. SUBDIRS = someLib someApp

someLib/someLib.mak:

  1. libsomeLib.so:
  2.         gcc foo.c -o libsomeLib.so
  3.  
  4. clean:
  5.         rm -f libsomeLib.so
  6.  
  7. distclean: clean
  8.  
  9. .PHONY: clean distclean

Note that it will create a bogus, non-functional “someLib/Makefile”, but you may simply ignore it.

I don’t believe this is documented, but it’s been in qmake for quite a long time (I want to say at least since 4.3.x, but don’t quote me on that).

Volker wrote:
Not quite true.

  1. HEADERS += plain.h base64.h
  2. SOURCES += main.cpp base64.c

This calls g++ (GCC in C++ mode) on main.cpp and gcc (GCC in C mode) on base64.c. The decision is made on the file extension (.cpp or .c). One can tweak that with setting QMAKE_EXT_CPP. The default is .cpp .cc .cxx .C

Thanks for all the suggestions, I was unable to go back to the project because of work but I will try the suggestions right away and get back to you.

Thanks everyone!

December 11, 2010

benardmens benardmens
Lab Rat
13 posts

Hi all,

I’ve tried the options without success so I’ve uploaded the project if some one could kindly help me out with where I’m going wrong. The link is below

http://www.wikiupload.com/3XHWP6JG2GXMU1D

Thanks again everyone for the help so far

December 11, 2010

GordonSchumacher GordonSchuma..
Lab Rat
93 posts

Is that really all of libhaggle? There is no Makefile in that directory, but there is Makefile.in/.ac, which would certainly suggest that it’s an Autotools project… but there is no Autoconf.in/.ac, so I can’t run automake at all (or at least, mine complains about the lack of those files).

December 11, 2010

benardmens benardmens
Lab Rat
13 posts
GordonSchumacher wrote:
Is that really all of libhaggle? There is no Makefile in that directory, but there is Makefile.in/.ac, which would certainly suggest that it’s an Autotools project… but there is no Autoconf.in/.ac, so I can’t run automake at all (or at least, mine complains about the lack of those files).

Hi Gordon, thanks for the quick reply, I actually didn’t include them because in my naivety i though they weren’t needed. Please find the full haggle folder included. By the way this is being compiled for Maemo (N900). Don’t know if that helps. The links are below. They are both the same thing just uploaded to different places for convenience.

http://www.wikiupload.com/QIPLU200EX9PHGS
http://rapidshare.com/files/436368610/Policy.zip

Thanks again every one, really appreciate the help

December 13, 2010

GordonSchumacher GordonSchuma..
Lab Rat
93 posts

Okay, that was way harder than it should have been, and my solution unquestionably qualifies as abusing qmake… but it works!

I created a “main.pro” in the top-level directory with the following contents:

  1. TEMPLATE = subdirs
  2.  
  3. haggle_build.subdir = haggle_build
  4. haggle_build.makefile = Makefile.haggle_build
  5.  
  6. PolicyMobile.subdir = PolicyMobile
  7. PolicyMobile.depends = haggle_build
  8.  
  9. SUBDIRS = haggle_build PolicyMobile

The “haggle_build.makefile = haggle_build” will cause the top-level Makefile to call “make -f Makefile.haggle_build” in that subdirectory. We need to change the name of the makefile because configure would otherwise clobber it. Note that this will not actually change the name of the file qmake generates there… we’ll take care of that in a bit.

Then I created a subdirectory called “haggle_build”. In that directory I placed a file named haggle_build.pro which contains:

  1. MAKEFILE = Makefile.haggle_build
  2.  
  3. HAGGLE_SRCDIR = ../haggle-0.3
  4.  
  5. autoreconf.target = $${HAGGLE_SRCDIR}/configure
  6. autoreconf.commands = cd $${HAGGLE_SRCDIR} && autoreconf
  7.  
  8. aclocal.target = $${HAGGLE_SRCDIR}/aclocal.m4
  9. aclocal.depends = autoreconf
  10.  
  11. automake.target = $${HAGGLE_SRCDIR}/Makefile.in
  12. automake.depends = autoreconf
  13.  
  14. autoheader.target = $${HAGGLE_SRCDIR}/Makefile.in
  15. autoheader.depends = autoreconf
  16.  
  17. libtoolize.target = $${HAGGLE_SRCDIR}/ltmain.sh
  18. libtoolize.depends = autoreconf
  19.  
  20. Makefile.target = Makefile
  21. Makefile.commands = $${HAGGLE_SRCDIR}/configure
  22. Makefile.depends = autoreconf aclocal automake autoheader libtoolize
  23.  
  24. all.CONFIG = phony
  25. all.commands = make
  26. all.depends = Makefile
  27.  
  28. TARGET = \\\
  29.  
  30. QMAKE_EXTRA_TARGETS += autoreconf aclocal automake autoheader libtoolize Makefile all

So the MAKEFILE variable changes the name of the makefile to match main.pro’s. Most of the rest of the .pro is writing custom targets to ensure that all the Autotools file are up-to-date. The last target, “all”, is one which qmake always generates, and is the default build target. I have not found a way to get qmake not to output a section which looks something like:

  1. all: $(TARGET)
  2.         $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)

Since we defined a custom rule named “all” as well and made it depend on “Makefile”, qmake will later on write another rule in the makefile. So we can successfully get the “all” target to invoke make for us; our remaining challenge is to get it not to call the linker!

So my tactic was to abuse qmake and define TARGET to simply a space. This means that the first “all” rule depends on nothing, and thus will never be run!

Hope this works for you and helps; I am planning to transfer this nugget to a wiki page…

January 4, 2011

benardmens benardmens
Lab Rat
13 posts

GordonSchumacher wrote:
Okay, that was way harder than it should have been, and my solution unquestionably qualifies as abusing qmake… but it works!

I created a “main.pro” in the top-level directory with the following contents:

  1. TEMPLATE = subdirs
  2.  
  3. haggle_build.subdir = haggle_build
  4. haggle_build.makefile = Makefile.haggle_build
  5.  
  6. PolicyMobile.subdir = PolicyMobile
  7. PolicyMobile.depends = haggle_build
  8.  
  9. SUBDIRS = haggle_build PolicyMobile

The “haggle_build.makefile = haggle_build” will cause the top-level Makefile to call “make -f Makefile.haggle_build” in that subdirectory. We need to change the name of the makefile because configure would otherwise clobber it. Note that this will not actually change the name of the file qmake generates there… we’ll take care of that in a bit.

Then I created a subdirectory called “haggle_build”. In that directory I placed a file named haggle_build.pro which contains:

  1. MAKEFILE = Makefile.haggle_build
  2.  
  3. HAGGLE_SRCDIR = ../haggle-0.3
  4.  
  5. autoreconf.target = $${HAGGLE_SRCDIR}/configure
  6. autoreconf.commands = cd $${HAGGLE_SRCDIR} && autoreconf
  7.  
  8. aclocal.target = $${HAGGLE_SRCDIR}/aclocal.m4
  9. aclocal.depends = autoreconf
  10.  
  11. automake.target = $${HAGGLE_SRCDIR}/Makefile.in
  12. automake.depends = autoreconf
  13.  
  14. autoheader.target = $${HAGGLE_SRCDIR}/Makefile.in
  15. autoheader.depends = autoreconf
  16.  
  17. libtoolize.target = $${HAGGLE_SRCDIR}/ltmain.sh
  18. libtoolize.depends = autoreconf
  19.  
  20. Makefile.target = Makefile
  21. Makefile.commands = $${HAGGLE_SRCDIR}/configure
  22. Makefile.depends = autoreconf aclocal automake autoheader libtoolize
  23.  
  24. all.CONFIG = phony
  25. all.commands = make
  26. all.depends = Makefile
  27.  
  28. TARGET = \\\
  29.  
  30. QMAKE_EXTRA_TARGETS += autoreconf aclocal automake autoheader libtoolize Makefile all

So the MAKEFILE variable changes the name of the makefile to match main.pro’s. Most of the rest of the .pro is writing custom targets to ensure that all the Autotools file are up-to-date. The last target, “all”, is one which qmake always generates, and is the default build target. I have not found a way to get qmake not to output a section which looks something like:

  1. all: $(TARGET)
  2.         $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)

Since we defined a custom rule named “all” as well and made it depend on “Makefile”, qmake will later on write another rule in the makefile. So we can successfully get the “all” target to invoke make for us; our remaining challenge is to get it not to call the linker!

So my tactic was to abuse qmake and define TARGET to simply a space. This means that the first “all” rule depends on nothing, and thus will never be run!

Hope this works for you and helps; I am planning to transfer this nugget to a wiki page…

Thanks a lot, there is no way I could have figured that out, I will try that right away and let you know how it goes,

Thanks again everyone

January 16, 2011

Mattias Cibien Mattias Cibien
Lab Rat
66 posts

I am also using qmake for my TicTacToe University Project which is coded in C and ncurses. I have no problems compiling C files.

 Signature 

http://mattias-cibien.co.cc
- Prepare for Qt consequences.

February 7, 2011

benardmens benardmens
Lab Rat
13 posts

GordonSchumacher wrote:
Okay, that was way harder than it should have been, and my solution unquestionably qualifies as abusing qmake… but it works!

I created a “main.pro” in the top-level directory with the following contents:

  1. TEMPLATE = subdirs
  2.  
  3. haggle_build.subdir = haggle_build
  4. haggle_build.makefile = Makefile.haggle_build
  5.  
  6. PolicyMobile.subdir = PolicyMobile
  7. PolicyMobile.depends = haggle_build
  8.  
  9. SUBDIRS = haggle_build PolicyMobile

The “haggle_build.makefile = haggle_build” will cause the top-level Makefile to call “make -f Makefile.haggle_build” in that subdirectory. We need to change the name of the makefile because configure would otherwise clobber it. Note that this will not actually change the name of the file qmake generates there… we’ll take care of that in a bit.

Then I created a subdirectory called “haggle_build”. In that directory I placed a file named haggle_build.pro which contains:

  1. MAKEFILE = Makefile.haggle_build
  2.  
  3. HAGGLE_SRCDIR = ../haggle-0.3
  4.  
  5. autoreconf.target = $${HAGGLE_SRCDIR}/configure
  6. autoreconf.commands = cd $${HAGGLE_SRCDIR} && autoreconf
  7.  
  8. aclocal.target = $${HAGGLE_SRCDIR}/aclocal.m4
  9. aclocal.depends = autoreconf
  10.  
  11. automake.target = $${HAGGLE_SRCDIR}/Makefile.in
  12. automake.depends = autoreconf
  13.  
  14. autoheader.target = $${HAGGLE_SRCDIR}/Makefile.in
  15. autoheader.depends = autoreconf
  16.  
  17. libtoolize.target = $${HAGGLE_SRCDIR}/ltmain.sh
  18. libtoolize.depends = autoreconf
  19.  
  20. Makefile.target = Makefile
  21. Makefile.commands = $${HAGGLE_SRCDIR}/configure
  22. Makefile.depends = autoreconf aclocal automake autoheader libtoolize
  23.  
  24. all.CONFIG = phony
  25. all.commands = make
  26. all.depends = Makefile
  27.  
  28. TARGET = \\\
  29.  
  30. QMAKE_EXTRA_TARGETS += autoreconf aclocal automake autoheader libtoolize Makefile all

So the MAKEFILE variable changes the name of the makefile to match main.pro’s. Most of the rest of the .pro is writing custom targets to ensure that all the Autotools file are up-to-date. The last target, “all”, is one which qmake always generates, and is the default build target. I have not found a way to get qmake not to output a section which looks something like:

  1. all: $(TARGET)
  2.         $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)

Since we defined a custom rule named “all” as well and made it depend on “Makefile”, qmake will later on write another rule in the makefile. So we can successfully get the “all” target to invoke make for us; our remaining challenge is to get it not to call the linker!

So my tactic was to abuse qmake and define TARGET to simply a space. This means that the first “all” rule depends on nothing, and thus will never be run!

Hope this works for you and helps; I am planning to transfer this nugget to a wiki page…

Hi Gordon,

I’ve been trying to replicate your solution for the past two weeks with varying levels of success, sometimes it compiles the files and then proceeds to fail. I was wondering if your solution is working for maemo as thats the target platform I’m trying to build for using the MADDE tools. Could you upload your solution so that I can go through it as I dont seem to be making much more headway.

Thanks a bunch

Page  
2

  ‹‹ QT Simulator under Windows 7 64bit does not work (does not exist?)      [solved][Mac OS X] Additional plugins for Qt (qca plugins) ››

You must log in to post a reply. Not a member yet? Register here!