I am trying to use the Qt Creator for Ansi C program development. My problem is that I am still getting typical for g++ warnings, such as variable length array used. Is there a way to force the Qt Creator to use gcc only and never g++ at any stage (compile, link etc)?
I've needed to think about this twice in the past, when building Qt/C++ projects that were using a subproject that I wanted to compile as a C static library in QtCreator: FluidSynth and Sonivox.
QtCreator has a wizard to create a plain C application (Welcome -> New Project -> Non-Qt Project -> Plain C Application:
The compiler is not a problem; qmake does the right thing based on the suffix of the source files: gcc for *.c, and g++ for *.cpp . You only need to worry about linking, and about LFLAGS and CFLAGS when they need particular values:
QMAKE_LINK = $$QMAKE_LINK_C
QMAKE_LFLAGS_RPATH = ...
QMAKE_CFLAGS_DEBUG = ...
QMAKE_CFLAGS_RELEASE = ...
Related
I'm trying to simulate "gcc -c program.c -o program.o" in automake Makefile.am to then be used in a shared library.
I have something like
lib_LTLIBRARIES = libsomething.la
libsomething_la_CPPFLAGS = -I/dir/
include_Headers = dir/neededHeader.h
libsomething_la_SOURCES = src/program.c
But this seems to go farther than the just creating a .o file and putting it in the library. The reason I'm trying to do this is I have c functions but do not give prototypes for them. They are declared externally in another file that links to the library trying to be created. Which if given prototypes in both locations would cause an error. I can do this from terminal commands and with making my own custom Makefile but want the portability of using automake.
I started experimenting with C/C++ the other day because I needed it for reading level-4 MAT-files without needing to purchase the Matlab editor or compiler. So I found just the library that I needed but I'm not familiar with C or C++ at all so I'm a beginner with those two languages. Anyhow I need to include the 'matio' library. I've tried many things but I've had no luck.
I right clicked on the C/C++ project > properties > C/C++ General > Paths & Symbols > GNU C and added the path to the matio library.
I also went to C/C++ Build > Settings > Tool settings > GCC C Compiler > Includes and added the path there aswell.
Since I'm not any good with makefiles yet I did not specify my own makefile, instead I chose a executable project.
When I try to build my project it complains about a function called 'Mat_Open' in the matio library. When I hover over it, it says "undefined reference to 'Mat_Open'" the header 'matio.h' seems to work fine but it can't refer to 'Mat_Open' for some reason.
How do I solve this?
EDIT:
Here is the whole build console output.
10:42:52 **** Incremental Build of configuration Debug for project Project ****
Info: Internal Builder is used for build
gcc -IC:/matio-1.5.2/src -O0 -g3 -Wall -c -fmessage-length=0 -o CComponent.o "..\\CComponent.c"
gcc -Xlinker -lm -o Project.exe CComponent.o -lC:/matio-1.5.2/src
c:/mingw(x64)/bin/../lib/gcc/x86_64-w64-mingw32/4.8.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lC:/matio-1.5.2/src
collect2.exe: error: ld returned 1 exit status
10:42:53 Build Finished (took 330ms)
This is not necessarily an answer but may be useful for a comparison.
First of all, where did you install it? If your using Linux or Mac OSX you will want to install in the system directories (not sure about Windows). I use OSX so in my makefile (by the way I use Qt):
LIBS += -L/usr/local/lib/ -lmatio
INCLUDEPATH += /usr/local/include
Then of course, in the *.h files of my source I use:
#include "matio.h"
But I assume you have already tried that?
I'm using eclipse for building a avr-gcc project that mixes assembly code and C source files.
I want to get rid of the automatic makefile generation of eclipse because I need to automate some process into the makefiles and for other reasons.
I used cmake some times ago and I was happy with it so I want to try to compile my source files using it. Everything run as expected with C sources. The problem is that at the end I need to compile some assembly files (actually 2) and add them to the target.
I googled around but I didn't found a way for doing this.
someone have an idea on how to do this?
The problem is that in eclipse I have
-x assembler-with-cpp
added to gcc argument list. I need to find a way for selectively add this param to the standard gcc argument list only for the asm files. I didn't find around any way for doing this.
thank you in advance
SOLUTION:
set in CMakeLists.txt every file to compile in the same list
enable_language(C ASM)
set ( SOURCES
foo.c
bar.c
foobar.s
)
add_executable(program ${SOURCES} )
in the Toolchain file you should place:
SET(ASM_OPTIONS "-x assembler-with-cpp")
SET(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS}" )
the second line is just if you need to pass extra options while compiling asm files. I wanted to pass all the CFLAGS plus some ASM_OPTIONS
CMake supports assembler out of the box. Just be sure to enable the "ASM" language in your project. If an assembler source file needs preprocessing, also set the source file's compilation options:
project(assembler C ASM)
set_property(SOURCE foo.s APPEND PROPERTY COMPILE_OPTIONS "-x" "assembler-with-cpp")
add_executable(hello foo.s bar.c)
Based on your solution, one of the simplest solutions is this one-liner:
SET(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp")
After having trouble extending a standard makefile for having (examples, clean, (un) install, etc) I decided to try autoconf.
The only documentation I could find is how to supply a file to be compiled and installed, but not a file that will be linked and installed in to a library location.
An example a tutorial gives me:
# what flags you want to pass to the C compiler & linker
CFLAGS = --pedantic -Wall -std=c99 -O2
LDFLAGS =
# this lists the binaries to produce, the (non-PHONY, binary) targets in
# the previous manual Makefile
bin_PROGRAMS = targetbinary1 targetbinary2 [...] targetbinaryN
targetbinary1_SOURCES = targetbinary1.c myheader.h [...]
targetbinary2_SOURCES = targetbinary2.c
.
.
targetbinaryN_SOURCES = targetbinaryN.c
Of course this seems a bit limiting as it does not expose where the Cflags (or LDFLAGS in the case I wish to have) go or if they are automatically applied.
bin_PROGRAMS can be a few other options but they only seem to be for including libraries (.la) rather than compiling one, or installing the compiled shared library to system.
Am I being a bit silly packaging my library so it can be ./configured and alike? Are there any base line guides for GNU make with this sort of packaging or informal conventions that would be easier doing this? I am looking forward to researching all my options.
I found the answer by using libtool with automake, this makes a lot more sense than handling platform-specific flags and such on my own.
I used f2c to translate a huge Fortran subroutine into C. The header says the following:
/* fourier.f -- translated by f2c (version 20090411).
You must link the resulting object file with libf2c:
on Microsoft Windows system, link with libf2c.lib;
on Linux or Unix systems, link with .../path/to/libf2c.a -lm
or, if you install libf2c.a in a standard place, with -lf2c -lm
-- in that order, at the end of the command line, as in
cc *.o -lf2c -lm
Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
http://www.netlib.org/f2c/libf2c.zip
*/
I am using ubuntu 10.04. How can I link the object file with libf2c?
You would have to install the libf2c2-dev package -- but as the f2c package already depends on it, all you may need is to add -lf2c to your Makefile.
Are you compiling the resulting C file with gcc? Then add "-lf2c -lm" to the gcc compile command.
Why not compile with a Fortran compiler, such as gfortran? It's easily available for Ubuntu.
By passing -lf2c -lm to the line which will create the executable from the objects. Which compiler are you using on Ubuntu? GCC?
gcc -c fourier.c -lf2c -lm
Could be as simple as that.
Well - no direct answer to your linking problems, but:
Since you're working with Linux: Why don't you compile you fortran code as is and link it directly with the C-code? GCC can do that. Converting the code is of course doable but it is by no way required.
Nils