[prev in list] [next in list] [prev in thread] [next in thread]
List: cmake
Subject: Re: [CMake] CMake+QT always failed for the first build, and succeeded for second build or later.
From: irene w <ire866306 () gmail ! com>
Date: 2016-05-31 14:52:41
Message-ID: CAFKdVOtZ0Fd-5Pp1uvhxAjx=UZi9kqPgLeT7Opq_dOOWYL++=g () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
It seems CMakw could not find the generated moc_xxx files. I modified the
scripts to specify moc_xxx files is generated, but it still has same errors.
ADD_CUSTOM_COMMAND ( OUTPUT ${Qt_tmp}/moc_GMWindow.cpp
COMMAND ${QT_MOC_CMD} ${GM_DIR}/GMWindow.h -o
${Qt_tmp}/moc_GMWindow.cpp
DEPENDS ${GM_DIR}/GMWindow.h
)
ADD_CUSTOM_TARGET(generate_foo DEPENDS ${Qt_tmp}/moc_GMWindow.cpp)
SET_SOURCE_FILES_PROPERTIES(${Qt_tmp}/moc_GMWindow.cpp PROPERTIES GENERATED
1)
SET_PROPERTY(SOURCE ${GM_DIR}/GMWindow.cpp APPEND PROPERTY OBJECT_DEPENDS
${Qt_tmp}/moc_GMWindow.cpp)
.....
add_dependencies (GM generate_foo)
Does the Macro "SET_SOURCE_FILES_PROPERTIES" with "GENERATED" setting work
for this purposes? Any help would be greatly appreciated !
On Wed, May 25, 2016 at 12:48 PM, irene w <ire866306@gmail.com> wrote:
> Hi,
>
> I am compiling a simple Qt3 application on Linux using CMake. In my case,
> I need to build moc_xxx files with custom options and output to a specified
> directory, So, I was not using CAMKE_AUTO macros. My cmake scripts create a
> "Qt_tmp" directory and output moc_xxx there.
>
> It looked it always failed to link the moc_xxx files for the first time
> build when there is no "Qt_tmp" directory, and succeeded if I ran build
> again if the "Qt_tmp" directory and moc_xxx files created by the failed
> build were kept without removing. However, it'll fail if I delete
> the "Qt_tmp" directory.
>
> Even it failed at the first build, the moc_xxx files were
> successfully created in the "Qt_tmp" directory.
>
> Here is my cmake scripts and the errors I got. Can anyone help me to
> figure out the issues? Any help would be greatly appreciated. Thanks.
>
> CMakeLists.txt
>
> ---------------------------------------------------------------------------------------------
> cmake_minimum_required(VERSION 3.4.1)
> project (GM_Application CXX)
> SET (CMAKE_SYSTEM_NAME Linux)
> SET (CMAKE_CXX_COMPILER ${COMPILER_PATH}${CROSS_COMPILE}g++)
> set (GM_DIR ${CMAKE_CURRENT_SOURCE_DIR})
> set (QT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/Qt/4.8.6)
> LINK_DIRECTORIES (${QT_DIR}/lib)
> INCLUDE_DIRECTORIES ("${QT_DIR}/include"
> "${GM_DIR}"
> )
> ##### Compiling QT moc and ui #####
> set (QT_MOC_CMD ${QT_DIR}/bin/moc -I$(QT_DIR)/mkspecs/linux-g++
> -I${QT_DIR}/include -I${QT_DIR}/include/QtGui)
> file (MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Qt_tmp)
> set (Qt_tmp ${CMAKE_CURRENT_SOURCE_DIR}/Qt_tmp)
> add_custom_target (Moc_GMWindows
> COMMAND ${QT_MOC_CMD} ${GM_DIR}/GMWindow.h -o
> ${Qt_tmp}/moc_GMWindow.cpp
> )
>
> ##### Compiling application #####
> file (GLOB GM_SOURCES ${GM_DIR}/*.h ${GM_DIR}/*.cpp)
> file (GLOB Moc_SOURCES ${Qt_tmp}/*.h ${Qt_tmp}/*.cpp)
> add_executable (GM ${GM_SOURCES} ${Moc_SOURCES})
> target_include_directories (GM PRIVATE ${Qt_tmp})
> add_dependencies (GM Moc_GMWindows)
> target_link_libraries (GM QtGui)
>
>
> -------------------------------------------------------------------------------------------
> Errors:
>
> Scanning dependencies of target Moc_GMWindows
> [ 0%] Built target Moc_GMWindows
> Scanning dependencies of target GM
> [ 14%] Building CXX object GM/CMakeFiles/GM.dir/GM/GM.cpp.o
> [ 42%] Building CXX object GM/CMakeFiles/GM.dir/GM/GMService.cpp.o
> [ 67%] Building CXX object GM/CMakeFiles/GM.dir/GM/GMWindow.cpp.o
> [ 85%] Building CXX object GM/CMakeFiles/GM.dir/GM/main.cpp.o
> [100%] Linking CXX executable ../bin/GM
> CMakeFiles/GM.dir/GM/GMWindow.cpp.o: In function
> `GM::GMWindow::emitAppendMessage(QStrin
> g)':
> /GM/GMWindow.cpp:217: undefined reference to
> `GM::GMWindow::appendMessage(QString)'
> CMakeFiles/GM.dir/GM/GMWindow.cpp.o:(.rodata._ZTVN2GM8GMWindowE[vtable for
> GM::GMWindow]
> +0x8): undefined reference to `GM::GMWindow::metaObject() const'
> CMakeFiles/GM.dir/GM/GMWindow.cpp.o:(.rodata._ZTVN2GM8GMWindowE[vtable for
> GM::GMWindow]
> +0xc): undefined reference to `GM::GMWindow::qt_metacast(char const*)'
> CMakeFiles/GM.dir/GM/GMWindow.cpp.o:(.rodata._ZTVN2GM8GMWindowE[vtable for
> GM::GMWindow]
> +0x10): undefined reference to
> `GM::GMWindow::qt_metacall(QMetaObject::Call, int, void**)'
> collect2: ld returned 1 exit status
> make[2]: *** [bin/GM] Error 1
> make[1]: *** [GM/CMakeFiles/GM.dir/all] Error 2
> make: *** [all] Error 2
>
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> \
> Virus-free. www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
> <#m_6400203814648417669_DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
[Attachment #5 (text/html)]
<div dir="ltr"><div>It seems CMakw could not find the generated moc_xxx files. I \
modified the scripts to specify moc_xxx files is generated, but it still has same \
errors.</div><div><br></div><div>ADD_CUSTOM_COMMAND ( OUTPUT \
${Qt_tmp}/moc_GMWindow.cpp<br> COMMAND \
${QT_MOC_CMD} ${GM_DIR}/GMWindow.h -o ${Qt_tmp}/moc_GMWindow.cpp</div><div> \
DEPENDS ${GM_DIR}/GMWindow.h <br> \
)<br>ADD_CUSTOM_TARGET(generate_foo DEPENDS \
${Qt_tmp}/moc_GMWindow.cpp)<br>SET_SOURCE_FILES_PROPERTIES(${Qt_tmp}/moc_GMWindow.cpp \
PROPERTIES GENERATED 1)<br>SET_PROPERTY(SOURCE ${GM_DIR}/GMWindow.cpp APPEND PROPERTY \
OBJECT_DEPENDS ${Qt_tmp}/moc_GMWindow.cpp)</div><div><br></div><div>.....</div><div>add_dependencies \
(GM generate_foo)</div><div><br></div><div><br></div><div>Does the Macro \
"SET_SOURCE_FILES_PROPERTIES" with "GENERATED" setting work for \
this purposes? Any help would be greatly appreciated \
!</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On \
Wed, May 25, 2016 at 12:48 PM, irene w <span dir="ltr"><<a \
href="mailto:ire866306@gmail.com" target="_blank">ire866306@gmail.com</a>></span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>I am \
compiling a simple Qt3 application on Linux using CMake. In my case, I need to build \
moc_xxx files with custom options and output to a specified directory, So, I was \
not using CAMKE_AUTO macros. My cmake scripts create a "Qt_tmp" directory \
and output moc_xxx there. </div><div><br></div><div>It looked it always failed to \
link the moc_xxx files for the first time build when there is no "Qt_tmp" \
directory, and succeeded if I ran build again if the "Qt_tmp" directory \
and moc_xxx files created by the failed build were kept without removing. \
However, it'll fail if I delete the "Qt_tmp" \
directory.</div><div><br></div><div>Even it failed at the first build, the moc_xxx \
files were successfully created in the "Qt_tmp" \
directory.</div><div><br></div><div>Here is my cmake scripts and the errors I got. \
Can anyone help me to figure out the issues? Any help would be greatly appreciated. \
Thanks.</div><div><br></div><div>CMakeLists.txt</div><div>---------------------------- \
-----------------------------------------------------------------</div><div>cmake_minimum_required(VERSION \
3.4.1)<br>project (GM_Application CXX)</div><div>SET (CMAKE_SYSTEM_NAME Linux)<br>SET \
(CMAKE_CXX_COMPILER ${COMPILER_PATH}${CROSS_COMPILE}g++)</div><div>set (GM_DIR \
${CMAKE_CURRENT_SOURCE_DIR})<br>set (QT_DIR \
${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/Qt/4.8.6)<br>LINK_DIRECTORIES \
(${QT_DIR}/lib)<br>INCLUDE_DIRECTORIES ("${QT_DIR}/include"<br> \
"${GM_DIR}"<br>)</div><div>##### Compiling QT moc and ui #####<br>set \
(QT_MOC_CMD ${QT_DIR}/bin/moc -I$(QT_DIR)/mkspecs/linux-g++ -I${QT_DIR}/include \
-I${QT_DIR}/include/QtGui)<br>file (MAKE_DIRECTORY \
${CMAKE_CURRENT_SOURCE_DIR}/Qt_tmp)<br>set (Qt_tmp \
${CMAKE_CURRENT_SOURCE_DIR}/Qt_tmp)<br>add_custom_target (Moc_GMWindows <br> \
COMMAND ${QT_MOC_CMD} ${GM_DIR}/GMWindow.h -o ${Qt_tmp}/moc_GMWindow.cpp<br> \
)<br> <br>##### Compiling application ##### <br>file (GLOB GM_SOURCES \
${GM_DIR}/*.h ${GM_DIR}/*.cpp)<br>file (GLOB Moc_SOURCES ${Qt_tmp}/*.h \
${Qt_tmp}/*.cpp)<br>add_executable (GM ${GM_SOURCES} \
${Moc_SOURCES})<br>target_include_directories (GM PRIVATE \
${Qt_tmp})<br>add_dependencies (GM Moc_GMWindows)<br>target_link_libraries (GM \
QtGui)</div><div><br></div><div>------------------------------------------------------ \
-------------------------------------</div><div>Errors:</div><div><br></div><div>Scanning \
dependencies of target Moc_GMWindows<br>[ 0%] Built target \
Moc_GMWindows<br>Scanning dependencies of target GM<br>[ 14%] Building CXX object \
GM/CMakeFiles/GM.dir/GM/GM.cpp.o<br>[ 42%] Building CXX object \
GM/CMakeFiles/GM.dir/GM/GMService.cpp.o<br>[ 67%] Building CXX object \
GM/CMakeFiles/GM.dir/GM/GMWindow.cpp.o<br>[ 85%] Building CXX object \
GM/CMakeFiles/GM.dir/GM/main.cpp.o<br>[100%] Linking CXX executable \
../bin/GM<br>CMakeFiles/GM.dir/GM/GMWindow.cpp.o: In function \
`GM::GMWindow::emitAppendMessage(QStrin<br>g)':<br>/GM/GMWindow.cpp:217: \
undefined reference to \
`GM::GMWindow::appendMessage(QString)'<br>CMakeFiles/GM.dir/GM/GMWindow.cpp.o:(.rodata._ZTVN2GM8GMWindowE[vtable \
for GM::GMWindow]<br>+0x8): undefined reference to `GM::GMWindow::metaObject() \
const'<br>CMakeFiles/GM.dir/GM/GMWindow.cpp.o:(.rodata._ZTVN2GM8GMWindowE[vtable \
for GM::GMWindow]<br>+0xc): undefined reference to `GM::GMWindow::qt_metacast(char \
const*)'<br>CMakeFiles/GM.dir/GM/GMWindow.cpp.o:(.rodata._ZTVN2GM8GMWindowE[vtable \
for GM::GMWindow]<br>+0x10): undefined reference to \
`GM::GMWindow::qt_metacall(QMetaObject::Call, int, void**)'<br>collect2: ld \
returned 1 exit status<br>make[2]: *** [bin/GM] Error 1<br>make[1]: *** \
[GM/CMakeFiles/GM.dir/all] Error 2<br>make: *** [all] Error \
2</div><div><br></div></div><div><br> <table \
style="border-top-color:rgb(211,212,222);border-top-width:1px;border-top-style:solid">
<tbody><tr>
<td style="width:55px;padding-top:13px"><a \
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" \
target="_blank"><img height="29" \
src="https://ipmcdn.avast.com/images/2016/icons/icon-envelope-tick-round-orange_184x116-v1.png"></a></td>
<td style="width:470px;color:rgb(65,66,78);line-height:18px;padding-top:12px;font-family:Arial,Helvetica,sans-serif;font-size:13px">Virus-free. \
<a style="color:rgb(68,83,234)" \
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" \
target="_blank">www.avast.com</a> </td>
</tr>
</tbody></table><a href="#m_6400203814648417669_DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2" \
height="1" width="1"></a></div> </blockquote></div><br></div>
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at: \
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more information \
on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at \
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic