1 Attachment(s)
Using external c/c++ api, setting up *.pro File
Hi friends,
I'm currently trying to use an external c/c++ api in Qt Creator. Its an NASA api to calculate Spacecraft and planetary trajectories. http://naif.jpl.nasa.gov/naif/toolkit.html
I just created a new widget project and edited the project file ,this is what is looks like.
Code:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qt_spice
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp\
$$PWD/cspice/src/cspice/*
HEADERS += mainwindow.h\
$$PWD/cspice/include/*
INCLUDEPATH += $$PWD/cspice/include/
LIBS += -lm
This is what my project tree looks like:
Attachment 11479
I included the api in my main.cpp and the indexing recognizes it.
Code:
#include "mainwindow.h"
#include <QApplication>
#include "SpiceUsr.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
I have used this api on this machine in the eclipse ide so the compilers are working fine.
When i try to compile i hit this problem (Compile Output):
Code:
16:32:32: Running steps for project qt_spice...
16:32:32: Configuration unchanged, skipping qmake step.
16:32:32: Starting: "/usr/bin/make"
/home/gordon/Qt/5.5/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../qt_spice/qt_spice.pro
gcc -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../qt_spice -I. -I../qt_spice/cspice/include -I../../5.5/gcc_64/include -I../../5.5/gcc_64/include/QtWidgets -I../../5.5/gcc_64/include/QtGui -I../../5.5/gcc_64/include/QtCore -I. -I../../5.5/gcc_64/mkspecs/linux-g++ -o mkprodct.o ../qt_spice/cspice/src/cspice/mkprodct.csh
gcc: warning: ../qt_spice/cspice/src/cspice/mkprodct.csh: linker input file unused because linking not done
gcc -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../qt_spice -I. -I../qt_spice/cspice/include -I../../5.5/gcc_64/include -I../../5.5/gcc_64/include/QtWidgets -I../../5.5/gcc_64/include/QtGui -I../../5.5/gcc_64/include/QtCore -I. -I../../5.5/gcc_64/mkspecs/linux-g++ -o rawio.o ../qt_spice/cspice/src/cspice/rawio.h
../qt_spice/cspice/src/cspice/rawio.h:20:27: error: unknown type name 'size_t'
extern int read(int,void*,size_t), write(int,void*,size_t);
^
../qt_spice/cspice/src/cspice/rawio.h:24:1: error: unknown type name 'FILE'
extern FILE *fdopen(int, const char*);
^
make: *** [rawio.o] Error 1
16:32:39: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project qt_spice (kit: Desktop Qt 5.5.1 GCC 64bit)
When executing step "Make"
16:32:39: Elapsed time: 00:07.
am i making a newbie mistake? have i missed something? Can anyone point me in the right direction? If more information is needed im glad to provide it I've been messing around with this problem for the last 3 days and im lightly frustrated :( thx in advance!
Re: Using external c/c++ api, setting up *.pro File
Guessing from the errors, some "basic" headers aren't included. This can happen, the problem is compiler (and IDE) dependent. Try to add
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <QtGlobal>
in some basic NASA header (which seems to be always included) and compile again. If you pass, you can check which of the above includes are unnecessary.
Re: Using external c/c++ api, setting up *.pro File
Thank you for taking your time!
I included theses and additional standard headers, but i still get the same result. I did some further research and followed the errors. This is where the compile crashes:
Code:
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MSDOS
#ifdef OPEN_DECL
extern int creat(const char*,int), open(const char*,int);
#endif
extern int close(int);
extern int read(int,void*,size_t), write(int,void*,size_t); <---- size_t
extern int unlink(const char*);
#ifndef _POSIX_SOURCE
#ifndef NON_UNIX_STDIO
extern FILE *fdopen(int, const char*);
#endif
#endif
#endif /*KR_HEADERS*/
extern char *mktemp(char*);
#ifdef __cplusplus
}
i followed where it is defined, like you said in one of the standard headers: stddef.h:
Code:
/* Define this type if we are doing the whole job,
or if we want this type in particular. */
#if defined (_STDDEF_H) || defined (__need_size_t)
#ifndef __size_t__ /* BeOS */
#ifndef __SIZE_T__ /* Cray Unicos/Mk */
#ifndef _SIZE_T /* in case <sys/types.h> has defined it. */
#ifndef _SYS_SIZE_T_H
#ifndef _T_SIZE_
#ifndef _T_SIZE
#ifndef __SIZE_T
#ifndef _SIZE_T_
#ifndef _BSD_SIZE_T_
#ifndef _SIZE_T_DEFINED_
#ifndef _SIZE_T_DEFINED
#ifndef _BSD_SIZE_T_DEFINED_ /* Darwin */
#ifndef _SIZE_T_DECLARED /* FreeBSD 5 */
#ifndef ___int_size_t_h
#ifndef _GCC_SIZE_T
#ifndef _SIZET_
#ifndef __size_t
#define __size_t__ /* BeOS */
#define __SIZE_T__ /* Cray Unicos/Mk */
#define _SIZE_T
#define _SYS_SIZE_T_H
#define _T_SIZE_
#define _T_SIZE
#define __SIZE_T
#define _SIZE_T_
#define _BSD_SIZE_T_
#define _SIZE_T_DEFINED_
#define _SIZE_T_DEFINED
#define _BSD_SIZE_T_DEFINED_ /* Darwin */
#define _SIZE_T_DECLARED /* FreeBSD 5 */
#define ___int_size_t_h
#define _GCC_SIZE_T
#define _SIZET_
#if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
|| defined(__FreeBSD_kernel__)
/* __size_t is a typedef on FreeBSD 5, must not trash it. */
#elif defined (__VMS__)
/* __size_t is also a typedef on VMS. */
#else
#define __size_t
#endif
#ifndef __SIZE_TYPE__
#define __SIZE_TYPE__ long unsigned int
#endif
#if !(defined (__GNUG__) && defined (size_t))
typedef __SIZE_TYPE__ size_t; <----------This is where i followed the definition
#ifdef __BEOS__
typedef long ssize_t;
#endif /* __BEOS__ */
#endif /* !(defined (__GNUG__) && defined (size_t)) */
#endif /* __size_t */
#endif /* _SIZET_ */
#endif /* _GCC_SIZE_T */
#endif /* ___int_size_t_h */
#endif /* _SIZE_T_DECLARED */
#endif /* _BSD_SIZE_T_DEFINED_ */
#endif /* _SIZE_T_DEFINED */
#endif /* _SIZE_T_DEFINED_ */
#endif /* _BSD_SIZE_T_ */
#endif /* _SIZE_T_ */
#endif /* __SIZE_T */
#endif /* _T_SIZE */
#endif /* _T_SIZE_ */
#endif /* _SYS_SIZE_T_H */
#endif /* _SIZE_T */
#endif /* __SIZE_T__ */
#endif /* __size_t__ */
#undef __need_size_t
#endif /* _STDDEF_H or __need_size_t. */
I dont understand to much about these standard set up files, but is it possible that i need to set some environment vars that eclipse or its make might be setting automatically? just a guess...
Re: Using external c/c++ api, setting up *.pro File
Maybe this API is meant to be built as a library instead of being part of the application build?
In this case the build system for the library might take care of some of these.
Cheers,
_
Re: Using external c/c++ api, setting up *.pro File
Thx for the reply! Like i said the api compiled and works like this in eclipse. BUT there is a folder/file called lib/cspice.a. How would i include that into the Project? Normally they have names like libcspice.a dont they? LIBS += -L$$pwd/cspice/lib -lcspice ? can i just include the the header like this? Should i change the lib name to libcspice.a? Thx
Added after 32 minutes:
Thx anda, your Input got me to the the right approch. I had to rename the library to libcspice.a and using symbolic links in the -L/.... did not get resolved properly.
Code:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qt_spice
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
# $$PWD/cspice/src/cspice/*
HEADERS += mainwindow.h
$$PWD/cspice/include/*
INCLUDEPATH += $$PWD/cspice/include/
LIBS += -L/home/gordon/Qt/Projects/qt_spice/cspice/lib -lcspice
can be marked as solved!