Compilation problem on Qt c++ on mac os x 10.8.5



  • Hi,

    I need to write some code for an application that uses a camera with ethernet connection. The company who made the camera has provided include files to read images from the camera. The files are : ImageLib.h , PvApi.h and PvRegIo.h and some librarie files libImagelib.a and libPvAPI.a and libPvAPI.dylib libPvJNI.dylib
    I put the librarie files in /opt/local/lib/. I put the include files in /opt/local/include/

    In the other hand, company provided some *.cpp examples that contains makefile for compilation. I compile some example and they worked perfectly.
    Now, I decide to compile one example provided by the company to list the connected cameras called ListCameras.cpp.
    I create a new project on QT and just I copied the code of ListCameras.cpp.
    My ListCameras.pro is like this:

    @QT += core
    QT -= gui
    TARGET = ListCameras
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    INCLUDEPATH+=/opt/local/include/
    LIBS+=-L/opt/local/lib/
    LIBS+= -llPvAPI
    LIBS+= -llPvJNI @

    Unfortunately, I have a lot of compilation errors.
    @12:21:15: Running steps for project ListCameras...
    12:21:15: Starting: "/usr/bin/make"
    clang++ -c -pipe -mmacosx-version-min=10.6 -g -gdwarf-2 -Wall -W -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_CORE_LIB -I../../5.0.2/clang_64/mkspecs/macx-clang -I../ListCameras -I/opt/local/include -I../../5.0.2/clang_64/include -I../../5.0.2/clang_64/include/QtCore -I../../5.0.2/clang_64/lib/QtCore.framework/Headers -I. -I. -o main.o ../ListCameras/main.cpp
    In file included from ../ListCameras/main.cpp:55:
    /opt/local/include/PvApi.h:97:26: error: Define PVDECL to be your compiler keyword for "standard call"
    #error Define PVDECL to be your compiler keyword for "standard call"
    ^
    /opt/local/include/PvApi.h:271:22: error: expected ')'
    typedef void (PVDECL tPvLinkCallback)(void Context,
    ^
    /opt/local/include/PvApi.h:271:14: note: to match this '('
    typedef void (PVDECL tPvLinkCallback)(void Context,
    ^
    /opt/local/include/PvApi.h:302:22: error: expected ')'
    typedef void (PVDECL tPvCameraEventCallback)(void Context,
    ^
    /opt/local/include/PvApi.h:302:14: note: to match this '('
    typedef void (PVDECL tPvCameraEventCallback)(void Context,
    ^
    /opt/local/include/PvApi.h:302:15: error: typedef redefinition with different types ('void (void *, tPvHandle, const tPvCameraEvent , unsigned long)' vs 'void (void , tPvInterface, tPvLinkEvent, unsigned long)')
    typedef void (PVDECL tPvCameraEventCallback)(void Context,
    ^
    /opt/local/include/PvApi.h:271:15: note: previous definition is here
    typedef void (PVDECL tPvLinkCallback)(void Context,
    ^
    /opt/local/include/PvApi.h:412:22: error: expected ')'
    typedef void (PVDECL tPvFrameCallback)(tPvFrame Frame);
    ^
    /opt/local/include/PvApi.h:412:14: note: to match this '('
    typedef void (PVDECL tPvFrameCallback)(tPvFrame Frame);
    ^
    /opt/local/include/PvApi.h:412:15: error: typedef redefinition with different types ('void (tPvFrame )' vs 'void (void , tPvInterface, tPvLinkEvent, unsigned long)')
    typedef void (PVDECL tPvFrameCallback)(tPvFrame Frame);
    ^
    /opt/local/include/PvApi.h:271:15: note: previous definition is here
    typedef void (PVDECL tPvLinkCallback)(void Context,
    ^
    /opt/local/include/PvApi.h:431:2: error: Define specific data types for your platform.
    #error Define specific data types for your platform.
    ^
    /opt/local/include/PvApi.h:508:6: error: variable has incomplete type 'void'
    void PVDECL PvVersion(unsigned long
    pMajor,unsigned long
    pMinor);
    ^
    /opt/local/include/PvApi.h:508:12: error: expected ';' after top level declarator
    void PVDECL PvVersion(unsigned long
    pMajor,unsigned long
    pMinor);
    ^
    ;
    /opt/local/include/PvApi.h:528:8: error: redefinition of 'PVDECL' as different kind of symbol
    tPvErr PVDECL PvInitialize(void);
    ^
    /opt/local/include/PvApi.h:271:15: note: previous definition is here
    typedef void (PVDECL tPvLinkCallback)(void Context,
    ^

    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    20 errors generated.
    make: *** [main.o] Error 1
    12:21:15: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project ListCameras (kit: Desktop Qt 5.0.2 clang 64bit)
    When executing step 'Make'
    12:21:15: Elapsed time: 00:00.@



  • Hi, try to add this to your .pro file
    @
    DEFINES += _OSX
    @

    also you can look at "this thread":https://qt-project.org/forums/viewthread/5673 (note: for Linux not Mac, but same problem)



  • Hello,
    Thanks! I resolved some errors by adding just

    @DEFINES += _x64 _OSX@

    but I got some errors like:

    @14:08:04: Running steps for project ListCameras...
    14:08:04: Starting: "/usr/bin/make"
    make: Nothing to be done for `first'.
    14:08:04: The process "/usr/bin/make" exited normally.
    14:08:04: Configuration unchanged, skipping qmake step.
    14:08:04: Could not start process ""
    Error while building/deploying project ListCameras (kit: Desktop Qt 5.0.2 clang 64bit)
    When executing step 'Custom Process Step'
    14:08:04: Elapsed time: 00:00.@



  • Good!
    About "make: Nothing to be done...": Maybe you need to refresh your project in QtCreator, do a Build/Run qmake
    (I think :-)



  • Hello,

    I think I have to add some others flags or libraries in ListCameras.pro but I do not which flags or librairies are missed.

    @QT += core

    QT -= gui

    TARGET = ListCameras
    CONFIG += console
    CONFIG -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    INCLUDEPATH+=/opt/local/include/
    LIBS+=-L/opt/local/lib/
    LIBS+= -lPvAPI
    LIBS+= -lPvJNI
    DEFINES += _x64 _OSX@

    The configuration file ARCH given by the company for all example is like this:

    @# Global ARCHitecture settings for the Sample code

    this file should be adapted to your platform

    Target CPU

    #CPU = x86
    CPU = x64

    Target OS

    OS = OSX
    OS_DIR = OSX

    OS-X version

    OSXV = -mmacosx-version-min=10.5

    architecture flags

    #ARCH = -m32

    compilation flags

    OPT = -O3 $(ARCH) $(OSXV)

    compiler version

    CVER = 4.2

    compiler

    #CC =g++-$(CVER)
    CC=g++

    linker

    LD = ld
    AR = ar
    SP = strip

    some flags

    DFLAGS = -D_$(CPU) -D_$(OS)
    #FLAGS = -fno-strict-aliasing -fexceptions -I/usr/include $(DFLAGS)
    FLAGS = -I/usr/include $(DFLAGS)

    TIFF library

    #LTIFF = -ltiff

    few locations

    INC_DIR = ../../inc-pc
    BIN_DIR = ../../bin-pc/$(CPU)
    LIB_DIR = ../../lib-pc/$(CPU)
    OBJ_DIR = ./obj/$(CPU)
    EXTRA_LIB = -lpthread -lz

    library

    LJPEG = -ljpeg

    libs (shared/static)

    PVLIB = -L$(BIN_DIR) -lPvAPI
    SOLIB = $(EXTRA_LIB) -Bdynamic -lm -lc
    SALIB = -Bstatic $(LIB_DIR)/$(CVER)/libPvAPI.a -framework CoreFoundation
    IMLIB = -Bstatic $(LIB_DIR)/$(CVER)/libImagelib.a -Bdynamic $(LTIFF)

    final compilation flags

    CFLAGS = $(OPT) $(FLAGS) -Wall -I$(INC_DIR) -D_REENTRANT $(EXTRA)@

    the makefile for the ListCameras example is:
    @# makefile of GigE SDK Sample code

    include ../ARCH

    Executable

    EXE = ListCameras

    $(OBJ_DIR)/%.o : %.cpp
    $(CC) $(CFLAGS) $(VERSION) -c $< -o $

    clean:
    rm $(EXE)

    sample : $(EXE).cpp
    $(CC) $(RPATH) $(TARGET) $(CFLAGS) $(EXE).cpp -o $(EXE) $(SOLIB) $(PVLIB)

    sample-static : $(EXE).cpp
    $(CC) $(RPATH) $(TARGET) $(CFLAGS) $(EXE).cpp $(SALIB) -o $(EXE) $(SOLIB)

    install:
    cp -f $(EXE) $(BIN_DIR)@



  • Ok, but what other errors apart from that "make: Nothing to be done...: do you see?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you do a clean rebuild after adding the defines ?



  • Hello,

    each time, i do clean all then rebuild!


  • Lifetime Qt Champion

    Did you add a custom process step ?



  • Hello,

    I have not used c++ for 7 or 8 years. So i do not understand what is custom process step.


  • Lifetime Qt Champion

    Nothing c++ specific,
    There's this line in your output

    @When executing step 'Custom Process Step'@

    So did you modify the build steps in the Projects panel ?



  • Thanks,

    Ok , to avoid all modification. I create an other project on Qt and I just copied the main.cpp code. I got a good news and bad news.

    good news: the Custum Process error is disappeared.
    bad news: when i execute i get a problem like @dyld: Library not loaded: libPvAPI.dylib @


  • Lifetime Qt Champion

    Go the run panel in the Projects panel.

    If it's not there, add a DYLD_LIBRARY_PATH environment variable in the "Run environment" part and as value put the path to the folder containing libPvAPI.dylib (if it already exists, add the path to the current list)



  • thanks a lot,

    It is progressing. I got a new errors. I learned a lots today. I cleaned and rebuild my project but I got this error.

    @dyld: Symbol not found: __cg_jpeg_resync_to_restart
    Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
    Expected in: /opt/local/lib//libJPEG.dylib
    in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO@



  • Hello,

    I did some research on google, developers suggests that we have to avoid use DYLD_LIBRARY_PATH because there is dynamic-linking-conflict between different libjpeg dynamic libraries on OSX . ("Conflict between dynamic linking priority in OSX?":http://stackoverflow.com/questions/17643509/conflict-between-dynamic-linking-priority-in-osx)


  • Lifetime Qt Champion

    Indeed, that's why I generally ensure that common dependencies I might have between libraries comes from a common place



  • Hello,

    I resolved the problem by put the library given in the SDK on the project folder. But, really I can not why when I configure it like:

    @DYLD_LIBRARY_PATH=/opt/local/bin@ it did not work and I get an error like @dyld: Symbol not found: __cg_jpeg_resync_to_restart
    Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
    Expected in: /opt/local/lib//libJPEG.dylib
    in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO@
    but when I copied the library form /opt/local/bin to the project folder, it work fine ??!! Any explication please ?


  • Lifetime Qt Champion

    @DYLD_LIBRARY_PATH=/opt/local/bin@

    you are pointing to the bin folder, the dylibs are in

    @DYLD_LIBRARY_PATH=/opt/local/lib@



  • Hello,

    Sorry, I made a mistake in my last post.

    In fact, I put@ DYLD_LIBRARY_PATH=/opt/local/lib@ but it does not work but when I copied the library form /opt/local/lib to the project folder, it work fine ??!! Any explication please ?


  • Lifetime Qt Champion

    Have a look at your application with otool -L you'll see what is linked.

    Then you also have the search order which is important



  • Hello,
    I run this command

    @otool -L main .o@
    but I did not get any output ?


  • Lifetime Qt Champion

    Not on main.o on the executable generated



  • Hello,

    I run @otool -L ListAllPrsilicaCameras@

    I get these output:
    @ListAllPrsilicaCameras:
    libPvAPI.dylib (compatibility version 0.0.0, current version 0.0.0)
    libPvJNI.dylib (compatibility version 0.0.0, current version 0.0.0)
    /opt/local/lib/libjpeg.9.dylib (compatibility version 11.0.0, current version 11.0.0)
    /Users/kifaraaouig/Qt/5.2.0/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.2.0, current version 5.2.0)
    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 60.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)@
    I remark that the problem is in
    @libPvAPI.dylib@

    When i put @DYLD_LIBRARY_PATH=/opt/local/lib@

    I get the error mentioned earlier but when I changed it like:

    @DYLD_LIBRARY_PATH=the project folder@

    What is the problem ?



  • Hi, welcome to Mac's version of DLL hell :-)

    I think it's because your app's otool -L references /opt/local/lib/libjpeg.9.dylib and otool -L on Apple's ImageIO.Framework (the one that gave the error message on Page 1) references /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJPEG.dylib.

    When you use the copied DLLs in your project's folder, I think the ImageIO.Framework loads Apple's libpjpeg.dylib and all is ok, but maybe in /opt/local/lib there's a symbolic link called libpjpeg.dylib, so in that case ImageIO.Framework thinks /opt/local/lib's libpjpeg.dylib is kosher to use (and hence the error, because it's not).

    Make sense? Anyway I think you need a more complete understanding exactly what dlls/dylibs are loaded. You can try with the lsof utility like this (first start your app and then open Terminal and type lsof -c and the first few letters of your app):
    lsof -c ListA

    Or lsof -c ListA | sort
    (in this case it's useful with a big Terminal window :-)



  • To trace what shared libraries get loaded in which order see:

    @man dyld@

    more precisely the variable DYLD_PRINT_LIBRARIES

    in short:

    @export DYLD_PRINT_LIBRARIES=1
    /path/to/your/app
    @



  • Hello,

    At the end, it is impossible to fix that in the case of

    @ DYLD_LIBRARY_PATH=/opt/local/lib@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.