Results 1 to 5 of 5

Thread: Using external c/c++ api, setting up *.pro File

  1. #1
    Join Date
    Oct 2015
    Posts
    33
    Thanks
    14
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default 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.

    Qt Code:
    1. QT += core gui
    2.  
    3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    4.  
    5. TARGET = qt_spice
    6.  
    7. TEMPLATE = app
    8.  
    9. SOURCES += main.cpp\
    10. mainwindow.cpp\
    11. $$PWD/cspice/src/cspice/*
    12.  
    13. HEADERS += mainwindow.h\
    14.   $$PWD/cspice/include/*
    15.  
    16. INCLUDEPATH += $$PWD/cspice/include/
    17.  
    18. LIBS += -lm
    To copy to clipboard, switch view to plain text mode 

    This is what my project tree looks like:

    project tree.png

    I included the api in my main.cpp and the indexing recognizes it.

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3. #include "SpiceUsr.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. MainWindow w;
    9. w.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    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):

    Qt Code:
    1. 16:32:32: Running steps for project qt_spice...
    2. 16:32:32: Configuration unchanged, skipping qmake step.
    3. 16:32:32: Starting: "/usr/bin/make"
    4. /home/gordon/Qt/5.5/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../qt_spice/qt_spice.pro
    5. 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
    6. gcc: warning: ../qt_spice/cspice/src/cspice/mkprodct.csh: linker input file unused because linking not done
    7. 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
    8. ../qt_spice/cspice/src/cspice/rawio.h:20:27: error: unknown type name 'size_t'
    9. extern int read(int,void*,size_t), write(int,void*,size_t);
    10. ^
    11. ../qt_spice/cspice/src/cspice/rawio.h:24:1: error: unknown type name 'FILE'
    12. extern FILE *fdopen(int, const char*);
    13. ^
    14. make: *** [rawio.o] Error 1
    15. 16:32:39: The process "/usr/bin/make" exited with code 2.
    16. Error while building/deploying project qt_spice (kit: Desktop Qt 5.5.1 GCC 64bit)
    17. When executing step "Make"
    18. 16:32:39: Elapsed time: 00:07.
    To copy to clipboard, switch view to plain text mode 

    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!

  2. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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
    Qt Code:
    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. #include <stddef.h>
    4. #include <QtGlobal>
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by Radek; 31st October 2015 at 17:07.

  3. #3
    Join Date
    Oct 2015
    Posts
    33
    Thanks
    14
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. #ifdef __cplusplus
    2. extern "C" {
    3. #endif
    4. #ifndef MSDOS
    5. #ifdef OPEN_DECL
    6. extern int creat(const char*,int), open(const char*,int);
    7. #endif
    8. extern int close(int);
    9. extern int read(int,void*,size_t), write(int,void*,size_t); <---- size_t
    10. extern int unlink(const char*);
    11. #ifndef _POSIX_SOURCE
    12. #ifndef NON_UNIX_STDIO
    13. extern FILE *fdopen(int, const char*);
    14. #endif
    15. #endif
    16. #endif /*KR_HEADERS*/
    17.  
    18. extern char *mktemp(char*);
    19.  
    20. #ifdef __cplusplus
    21. }
    To copy to clipboard, switch view to plain text mode 

    i followed where it is defined, like you said in one of the standard headers: stddef.h:

    Qt Code:
    1. /* Define this type if we are doing the whole job,
    2.   or if we want this type in particular. */
    3. #if defined (_STDDEF_H) || defined (__need_size_t)
    4. #ifndef __size_t__ /* BeOS */
    5. #ifndef __SIZE_T__ /* Cray Unicos/Mk */
    6. #ifndef _SIZE_T /* in case <sys/types.h> has defined it. */
    7. #ifndef _SYS_SIZE_T_H
    8. #ifndef _T_SIZE_
    9. #ifndef _T_SIZE
    10. #ifndef __SIZE_T
    11. #ifndef _SIZE_T_
    12. #ifndef _BSD_SIZE_T_
    13. #ifndef _SIZE_T_DEFINED_
    14. #ifndef _SIZE_T_DEFINED
    15. #ifndef _BSD_SIZE_T_DEFINED_ /* Darwin */
    16. #ifndef _SIZE_T_DECLARED /* FreeBSD 5 */
    17. #ifndef ___int_size_t_h
    18. #ifndef _GCC_SIZE_T
    19. #ifndef _SIZET_
    20. #ifndef __size_t
    21. #define __size_t__ /* BeOS */
    22. #define __SIZE_T__ /* Cray Unicos/Mk */
    23. #define _SIZE_T
    24. #define _SYS_SIZE_T_H
    25. #define _T_SIZE_
    26. #define _T_SIZE
    27. #define __SIZE_T
    28. #define _SIZE_T_
    29. #define _BSD_SIZE_T_
    30. #define _SIZE_T_DEFINED_
    31. #define _SIZE_T_DEFINED
    32. #define _BSD_SIZE_T_DEFINED_ /* Darwin */
    33. #define _SIZE_T_DECLARED /* FreeBSD 5 */
    34. #define ___int_size_t_h
    35. #define _GCC_SIZE_T
    36. #define _SIZET_
    37. #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
    38. || defined(__FreeBSD_kernel__)
    39. /* __size_t is a typedef on FreeBSD 5, must not trash it. */
    40. #elif defined (__VMS__)
    41. /* __size_t is also a typedef on VMS. */
    42. #else
    43. #define __size_t
    44. #endif
    45. #ifndef __SIZE_TYPE__
    46. #define __SIZE_TYPE__ long unsigned int
    47. #endif
    48. #if !(defined (__GNUG__) && defined (size_t))
    49. typedef __SIZE_TYPE__ size_t; <----------This is where i followed the definition
    50. #ifdef __BEOS__
    51. typedef long ssize_t;
    52. #endif /* __BEOS__ */
    53. #endif /* !(defined (__GNUG__) && defined (size_t)) */
    54. #endif /* __size_t */
    55. #endif /* _SIZET_ */
    56. #endif /* _GCC_SIZE_T */
    57. #endif /* ___int_size_t_h */
    58. #endif /* _SIZE_T_DECLARED */
    59. #endif /* _BSD_SIZE_T_DEFINED_ */
    60. #endif /* _SIZE_T_DEFINED */
    61. #endif /* _SIZE_T_DEFINED_ */
    62. #endif /* _BSD_SIZE_T_ */
    63. #endif /* _SIZE_T_ */
    64. #endif /* __SIZE_T */
    65. #endif /* _T_SIZE */
    66. #endif /* _T_SIZE_ */
    67. #endif /* _SYS_SIZE_T_H */
    68. #endif /* _SIZE_T */
    69. #endif /* __SIZE_T__ */
    70. #endif /* __size_t__ */
    71. #undef __need_size_t
    72. #endif /* _STDDEF_H or __need_size_t. */
    To copy to clipboard, switch view to plain text mode 

    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...
    Last edited by Lumbricus; 31st October 2015 at 17:41.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Lumbricus (1st November 2015)

  6. #5
    Join Date
    Oct 2015
    Posts
    33
    Thanks
    14
    Qt products
    Qt5
    Platforms
    Unix/X11

    Thumbs up 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.

    Qt Code:
    1. QT += core gui
    2.  
    3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    4.  
    5. TARGET = qt_spice
    6.  
    7. TEMPLATE = app
    8.  
    9. SOURCES += main.cpp\
    10. mainwindow.cpp
    11. # $$PWD/cspice/src/cspice/*
    12.  
    13. HEADERS += mainwindow.h
    14. $$PWD/cspice/include/*
    15.  
    16. INCLUDEPATH += $$PWD/cspice/include/
    17.  
    18. LIBS += -L/home/gordon/Qt/Projects/qt_spice/cspice/lib -lcspice
    To copy to clipboard, switch view to plain text mode 

    can be marked as solved!
    Last edited by Lumbricus; 1st November 2015 at 11:48.

Similar Threads

  1. QWebView & external css file
    By folibis in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2013, 22:42
  2. Using external Json file in QML
    By Kelteseth in forum Qt Quick
    Replies: 0
    Last Post: 30th November 2012, 17:08
  3. Qt Designer Use external stylesheet file (qss)
    By florianwalter in forum Qt Tools
    Replies: 0
    Last Post: 27th May 2010, 11:57
  4. QML file not loading external JS file?
    By anothertest in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2010, 09:11
  5. Database: How to use an external file?
    By goes2bob in forum Newbie
    Replies: 10
    Last Post: 23rd January 2008, 14:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.