Hello guys,
I'm trying to use the TRY_COMPILE command and I guess I'm probaly
making some mistake or I misunderstood the command.
My command is this one:
TRY_COMPILE(RESULT ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/teste.cpp
CMAKE_FLAGS
COMPILE_DEFINITIONS -I${QT_INCLUDE_DIR}
-I${QT_QTCORE_INCLUDE_DIR}
-l${QT_QTCORE_LIBRARY}
OUTPUT_VARIABLE MY_OUT
)
My compile parameters (-I) are working, but my link parameter
is just throw away when compiling and, to link, it's no used. MY_OUT
output is this: (I just marked the important commands to try to make it
more readable).
-- Found Qt-Version 4.2.0
-- Trycompile teste: FALSE
-- MY_OUT: /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make
CMakeFiles/cmTryCompileExec.dir/build
make[1]: entrant dans le répertoire «
/users/qgar/vasconcv/studies/QgarGui/build/CMakeFiles/CMakeTmp »
/usr/local/bin/cmake -E cmake_progress_report
/users/qgar/vasconcv/studies/QgarGui/build/CMakeFiles/CMakeTmp/CMakeFiles 1
-----------------------------------------------------------------------------
Building CXX object CMakeFiles/cmTryCompileExec.dir/teste.o
/usr/bin/c++ -I/usr/include/qt4 -I/usr/include/qt4/QtCore -o
CMakeFiles/cmTryCompileExec.dir/teste.o -c
/users/qgar/vasconcv/studies/QgarGui/teste.cpp
-----------------------------------------------------------------------------
Linking CXX executable cmTryCompileExec
/usr/local/bin/cmake -P
CMakeFiles/cmTryCompileExec.dir/cmake_clean_target.cmake
/usr/bin/c++ -fPIC "CMakeFiles/cmTryCompileExec.dir/teste.o" -o
cmTryCompileExec -rdynamic
-----------------------------------------------------------------------------
CMakeFiles/cmTryCompileExec.dir/teste.o: In function
`QString::QString(char const*)':
teste.cpp:(.text._ZN7QStringC1EPKc[QString::QString(char const*)]+0x15):
référence indéfinie vers « QString::fromAscii_helper(char const*, int)»
CMakeFiles/cmTryCompileExec.dir/teste.o: In function `QString::~QString()':
teste.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x23): référence
indéfinie vers « QString::free(QString::Data*)»
collect2: ld returned 1 exit status
make[1]: *** [cmTryCompileExec] Erreur 1
make[1]: quittant le répertoire «
/users/qgar/vasconcv/studies/QgarGui/build/CMakeFiles/CMakeTmp »
make: *** [cmTryCompileExec/fast] Erreur 2
-- Configuring done
-- Generating done
Thanks a lot in advance and have a nice day (or night),
--
Vitor VASCONCELOS
Projet QGAR
LORIA / INRIA-Lorraine
Campus Scientifique, BP 239
54506, Vandoeuvre-lès-Nancy, FRANCE
Tel: +33 (0)3 54 95 85 76
--
Vitor VASCONCELOS
Projet QGAR
LORIA / INRIA-Lorraine
Campus Scientifique, BP 239
54506, Vandoeuvre-lès-Nancy, FRANCE
Tel: +33 (0)3 54 95 85 76
Post by Vitor Vasconcelos Araujo Silva
Hello guys,
I'm trying to use the TRY_COMPILE command and I guess I'm probaly
making some mistake or I misunderstood the command.
TRY_COMPILE(RESULT ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/teste.cpp
CMAKE_FLAGS
COMPILE_DEFINITIONS -I${QT_INCLUDE_DIR}
-I${QT_QTCORE_INCLUDE_DIR}
-l${QT_QTCORE_LIBRARY}
OUTPUT_VARIABLE MY_OUT
)
My compile parameters (-I) are working, but my link parameter is
just throw away when compiling and, to link, it's no used. MY_OUT output
is this: (I just marked the important commands to try to make it more
readable).
You are missing LINK_LIBRARIES from Qt. I don't see where you are
passing a link parameter in??
-Bill
Thanks for your answer Bill,
I cutted from the example code the LINK_LIBRARIES, sorry.
I use the Qt4 macro and I get my application compiled without any problems.
FIND_PACKAGE ( Qt4 )
ADD_DEFINITIONS ( ${QT_DEFINITIONS} )
INCLUDE_DIRECTORIES ( ${QT_INCLUDE_DIR} )
INCLUDE_DIRECTORIES ( ${QT_QTCORE_INCLUDE_DIR} )
INCLUDE_DIRECTORIES ( ${QT_QTGUI_INCLUDE_DIR} )
INCLUDE_DIRECTORIES ( "../" )
LINK_DIRECTORIES ( ${QT_LIBRARY_DIR} )
SET ( GUI_SOURCES
QGAbstractLayer.cpp
QGDocViewer.cpp
QGImageLoader.cpp
QGMainWindow.cpp
QGMainWindowSubjectIf.cpp
QGMultiLayerDoc.cpp
QGPixmapLayer.cpp
QGMenu.cpp
QGFileMenu.cpp
QGRecentFileMenu.cpp
QGAbstractMainWindowCommand.cpp
QGOpenImageCommand.cpp
QGCloseImageCommand.cpp
QGEditMenu.cpp
QGZoomCommand.cpp
QGCommandToolBar.cpp
QGMainToolBar.cpp
QGUndoList.cpp
QGMainToolsToolBar.cpp
QGMouseTracker.cpp
QGSIModeCommand.cpp
main.cpp )
INCLUDE_DIRECTORIES ( ${PROJECT_SOURCE_DIR} )
SET ( QT_EXECUTABLE_NAME "Qt" )
ADD_EXECUTABLE ( ${QT_EXECUTABLE_NAME} ${GUI_SOURCES} )
SET(INCLUDE_DIRECTORIES ${QT_INCLUDE_DIR})
SET(LINK_LIBRARIES ${QT_QTCORE_LIBRARY})
After this code I call the TRY_COMPILE command. Note that I defined
the INCLUDE_DIRECTORIES and LINK_LIBRARIES variables guessing they
should be used like this.
Post by Bill Hoffman
Post by Vitor Vasconcelos Araujo Silva
TRY_COMPILE(RESULT ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/teste.cpp
CMAKE_FLAGS
COMPILE_DEFINITIONS -I${QT_INCLUDE_DIR}
-I${QT_QTCORE_INCLUDE_DIR}
-l${QT_QTCORE_LIBRARY}
OUTPUT_VARIABLE MY_OUT
)
You are missing LINK_LIBRARIES from Qt. I don't see where you are
passing a link parameter in??
-Bill
And, after the TRY_COMPILE block I finish my CMakeLists defining the
which libraries I want to link to my application.
TARGET_LINK_LIBRARIES ( ${QT_EXECUTABLE_NAME}
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
)
Thanks in advance,
--
Vitor VASCONCELOS
Projet QGAR
LORIA / INRIA-Lorraine
Campus Scientifique, BP 239
54506, Vandoeuvre-lès-Nancy, FRANCE
Tel: +33 (0)3 54 95 85 76
Post by Vitor Vasconcelos Araujo Silva
Post by Bill Hoffman
Post by Vitor Vasconcelos Araujo Silva
TRY_COMPILE(RESULT ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/teste.cpp
CMAKE_FLAGS
COMPILE_DEFINITIONS -I${QT_INCLUDE_DIR}
-I${QT_QTCORE_INCLUDE_DIR}
-l${QT_QTCORE_LIBRARY}
OUTPUT_VARIABLE MY_OUT
)
You are missing LINK_LIBRARIES from Qt. I don't see where you are
passing a link parameter in??
-Bill
And, after the TRY_COMPILE block I finish my CMakeLists defining the
which libraries I want to link to my application.
TARGET_LINK_LIBRARIES ( ${QT_EXECUTABLE_NAME}
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
)
Thanks in advance,
See the docs for try_compile:
http://www.cmake.org/HTML/cmake-2.6.html#command_try_compile
....
Some extra flags that can be included are, INCLUDE_DIRECTORIES,
LINK_DIRECTORIES, and LINK_LIBRARIES. COMPILE_DEFINITIONS are
-Ddefinition that will be passed to the compile line. try_compile
creates a CMakeList.txt file on the fly that looks like this:
add_definitions( <expanded COMPILE_DEFINITIONS from calling cmake>)
include_directories(${INCLUDE_DIRECTORIES})
link_directories(${LINK_DIRECTORIES})
add_executable(cmTryCompileExec sources)
target_link_libraries(cmTryCompileExec ${LINK_LIBRARIES})
....
You have this:
TRY_COMPILE(RESULT ${PROJECT_BINARY_DIR}
Post by Vitor Vasconcelos Araujo Silva
Post by Bill Hoffman
Post by Vitor Vasconcelos Araujo Silva
${PROJECT_SOURCE_DIR}/teste.cpp
CMAKE_FLAGS
COMPILE_DEFINITIONS -I${QT_INCLUDE_DIR}
-I${QT_QTCORE_INCLUDE_DIR}
-l${QT_QTCORE_LIBRARY}
OUTPUT_VARIABLE MY_OUT
)
You need to add:
LINK_LIBRARIES ${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
To the TRY_COMPILE call that you have.
-Bill
Post by Vitor Vasconcelos Araujo Silva
Hello guys,
I'm trying to use the TRY_COMPILE command and I guess I'm probaly
making some mistake or I misunderstood the command.
TRY_COMPILE(RESULT ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/teste.cpp
CMAKE_FLAGS
COMPILE_DEFINITIONS -I${QT_INCLUDE_DIR}
-I${QT_QTCORE_INCLUDE_DIR}
-l${QT_QTCORE_LIBRARY}
OUTPUT_VARIABLE MY_OUT
)
Did you try to use the macros CHECK_CXX_SOURCE_COMPILES() and friends which
come with cmake ?
What's missing there ?
Alex
replies
Can someone help me on this stupid syntax error in this java program I'm trying
to
write. Implementing class?
started
2007-10-15 14:53:19 UTC