When I try to compile my test app it fails.
CMakeLists.txt:
cmake_minimum_required( VERSION 2.8.8 )
project( webkit-test )
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package( Qt5Core )
find_package( Qt5Gui )
find_package( Qt5OpenGL )
find_package( Qt5Network )
find_package( Qt5WebKit )
find_package( Qt5Widgets )
add_executable( webkit-test main.cpp )
qt5_use_modules( webkit-test Core Gui OpenGL Network WebKit Widgets )
C++ code:
#include <QtWidgets/QApplication>
#include <QtWebKit/QWebView>
int main( int argc, char *argv[] )
{
QString file;
if ( argc >= 2 )
file = argv[1];
QApplication a( argc, argv );
return a.exec();
}
I generate makefile by cmake -G "NMake Makefiles" (3) and then use nmake (4).
After I received that I used dumpbin /EXPORTS QtWebKit5.dll > QtWebKit5.dll.exports.txt and dumpbin /EXPORTS QtWebKit5.lib > QtWebKit5.lib.exports.txt for seeing to exporting symbols: (5) and (6).
By using Ctrl+F you can find in these files "unresolved" external symbols:
?staticMetaObject#QWebPage##2UQMetaObject##B (public: static struct QMetaObject const QWebPage::staticMetaObject)
?staticMetaObject#QWebView##2UQMetaObject##B (public: static struct QMetaObject const QWebView::staticMetaObject)
If symbols are in QtWebKit5.lib, why I have these errors when linking?
some reasons affect to this,
if you use Qt with version greater than 4.7, add this namespace to your project's ".pro" file:
QT += webkitwidgets
and if less equals than 4.7:
QT += webkit
and change your QWebView library to (if gets a warning about "No such file or directory" do not worry!)
#include <QwebView>
I added add_definitions(-DQT_DLL) to my CMakeLists.txt and now it's compiled.
Related
I'm attempting to compile a "Hello World!" application using Qt but on compilation I'm getting the following error: ‘class QApplication’ has no member named ‘setMainWidget’ and I'm not sure why, my source file looks like:
/****************************************************************
**
** Qt tutorial 1
**
****************************************************************/
#include <qapplication.h>
#include <qpushbutton.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );
a.setMainWidget( &hello );
hello.show();
return a.exec();
}
and I created the Makefile with cmake using following CMakeLists.txt:
cmake_minimum_required(VERSION 3.1.0)
project(hello_world)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed
set(CMAKE_AUTOMOC ON)
# Create code from a list of Qt designer ui files
#set(CMAKE_AUTOUIC ON)
# Find the QtWidgets library
find_package(Qt5 COMPONENTS Widgets REQUIRED)
# Populate a CMake variable with the sources
set(hello_world_SRCS
main.cpp
)
# Tell CMake to create the helloworld executable
add_executable(hello_world WIN32 ${hello_world_SRCS})
# Use the Widgets module from Qt 5
target_link_libraries(hello_world Qt5::Widgets)
What am I doing wrong?
I am getting error (**
**> CMakeFiles\untitled3.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x46):
undefined reference to `_imp___ZN9osgViewer6ViewerC1Ev'**)
while adding OpenSceneGraph in Qt. My profile is cmakelist.txt.
cmake_minimum_required(VERSION 2.8.12)
project(untitled3)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Core)
FIND_PATH(OPENSCENEGRAPH_INCLUDE_DIR osg/Referenced
PATHS
$ENV{OSG_ROOT}/include
$ENV{OSG_DIR}/include
/usr/include
/usr/local/include
)
FIND_PATH(OPENSCENEGRAPH_LIB_DIR libosg.so osg.lib
PATHS
$ENV{OSG_ROOT}/lib
$ENV{OSG_DIR}/lib
/usr/lib
/usr/local/lib
)
INCLUDE_DIRECTORIES(common ${OPENSCENEGRAPH_INCLUDE_DIR})
LINK_DIRECTORIES(${OPENSCENEGRAPH_LIB_DIR})
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} Qt5::Core)
My main.cpp file is
#include <QCoreApplication>
#include <osgViewer/Viewer>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
osgViewer::Viewer viewer;
// viewer.setSceneData( osgDB::readNodeFile("cessna.osg") );
// return viewer.run();
return a.exec();
}
Any folks who can help. I invite them to come forward.
There is a problem with your cmake file. You need to make sure to:
Find the necessary OSG packages (osgViewer in your case).
Link your executable to the target OSG libraries.
Just like you did it for QtCore:
find_package(Qt5Core)
find_package(OpenSceneGraph REQUIRED COMPONENTS osgViewer)
# ...
target_link_libraries(${PROJECT_NAME} Qt5::Core ${OPENSCENEGRAPH_LIBRARIES} )
I am new to qtCreator and cmake. I have a project with a CMakeLists.txt which is working correctly.
I have a file main.cpp which contains the
int main(int argc, char *argv[])
{
...
}
At the top of this file I have several includes like:
...
#include <visp/vpImageIo.h>
#include <visp/vpPixelMeterConversion.h>
#include <visp/vpPose.h>
...
They are working correctly thanks to the CMakeLists.txt file which is the following:
cmake_minimum_required(VERSION 2.8)
project( opencv_apriltag2_flea )
set( CMAKE_BUILD_TYPE Release)
set( CMAKE_BUILD_DIRECTORY "/home/fschiano/Repositories/apriltag2/example")
#DEBUG
message( "CMAKE_BUILD_DIRECTORY=${CMAKE_BUILD_DIRECTORY}")
find_package( OpenCV REQUIRED )
find_package(VISP REQUIRED)
include_directories("/home/fschiano/Repositories/apriltag2")
include_directories("/home/fschiano/Repositories/apriltag2/common")
include_directories("usr/local")
include_directories("/home/fschiano/Repositories/visp/visp/modules/vision/src")
find_library(FLYCAPTURE2 flycapture)
add_executable( opencvDemo opencv_demo.cc )
include_directories(${VISP_INCLUDE_DIRS})
#DEBUG
message( "VISP_INCLUDE_DIRS=${VISP_INCLUDE_DIRS}")
message( "VISP_LIBRARIES=${VISP_LIBRARIES}")
# Needed libraries
set (EXTRA_LIBS apriltag flycapture ${OpenCV_LIBS} ${VISP_LIBRARIES})
target_link_libraries( opencvDemo ${EXTRA_LIBS} )
The problem is the following.
If I do :
vpPose pose; // Create an istance of vpPose
and then
point[i].set_x(x);
point[i].set_y(y);
pose.addPoint(point[i]);
where point has been declared before.
Everything works but, in QTCreator, I am not able to look at the implementation of the function addPoint(). This is the same for every function I have in my code which is related to visp.
In my opinion is because I am using this software (ViSP) as an external library and therefore qtCreator is looking only at the compiled version of the file related to it and it has no knowledge about where to search for the .cpp files.
I think I need to change something in the CMakeLists.txt file.
I tried by including the line:
include_directories("/home/fschiano/Repositories/visp/visp/modules/vision/src")
Where my .cpp file is. But it is not working.
Any ideas?
Thanks
I am trying to make a testbench to my program using gmock/gtest; Linux/Ubuntu; KDevelop/CMake. From the link error message I conclude that part of the gtest package is missing pthread support.
/home/projects/cpp/gmock/gtest/libgtest.a(gtest-all.cc.o): In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::~ThreadLocal()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x16): undefined reference to `pthread_getspecific'
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x2b): undefined reference to `pthread_key_delete'
I also read
googletest: how to setup?
Using g++ directly, everything works. So, since I am usinc KDevelop/CMake, I suspect either my code or CMake.
In my CMakeLists.txt I do use
add_definitions( -pthread -m64)
However, I do not see any effect in the Makefile.
Am I missing something from my CMakeLists.txt, or CMake does not consider the line above?
My CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
add_definitions( -Dpthread )
project(ThreadTest)
INCLUDE_DIRECTORIES(gmock/gtest/include)
set ( GTEST_LIBS libgtest.a )
link_directories( ~/projects/cpp/gmock/gtest)
add_executable(ThreadTest main_test.cpp)
target_link_libraries(ThreadTest ${GTEST_LIBS})
Do I misunderstand, that add_definitions should work in this situation?
After reading
How do I force cmake to include "-pthread" option during compilation?
my question really looks like duplicate. However,
cmake_minimum_required(VERSION 2.8)
add_definitions( -Dpthread )
project(ThreadTest)
INCLUDE_DIRECTORIES(gmock/gtest/include)
find_package( Threads )
set ( GTEST_LIBS libgtest.a )
link_directories( ~/projects/cpp/gmock/gtest)
add_executable(ThreadTest main_test.cpp)
target_link_libraries(ThreadTest ${GTEST_LIBS} ${CMAKE_THREAD_LIBS_INIT})
still gives the warning 'Could NOT find Threads'. I tried to search Ubuntu software center for "threads", with no result. After that, I installed libghc-threads-dev. However, when using
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
I keep receiving 'Could NOT find Threads', as error. What shall I do to satisfy find_package, and why do I have this problem, when the simple Makefile produces what I expect?
PS: my main file:
#include "gmock/gtest/include/gtest/gtest.h"
TEST(blahTest, blah1) {
EXPECT_EQ(1, 1);
}
int main (int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
int returnValue;
returnValue = RUN_ALL_TESTS();
return returnValue;
}
After busy hours, I succeeded to compile my supercomplex test program, using KDevelop/CMake/gtest
#include "gtest-1.7.0/include/gtest/gtest.h"
TEST(blahTest, blah1) {
EXPECT_EQ(1, 1);
}
int main (int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
The CMakeLists.txt file that could do the task is
# http://stackoverflow.com/questions/13513905/how-to-properly-setup-googletest-on-linux/13513907#13513907
# http://stackoverflow.com/questions/15193785/how-to-get-cmake-to-recognize-pthread-on-ubuntu
# http://stackoverflow.com/questions/21116622/undefined-reference-to-pthread-key-create-linker-error
# http://stackoverflow.com/questions/1620918/cmake-and-libpthread
# https://meekrosoft.wordpress.com/2009/10/04/testing-c-code-with-the-googletest-framework/
# http://stackoverflow.com/questions/30106608/googletest-cmake-and-make-tests-not-running
# http://stackoverflow.com/questions/13521618/c-project-organisation-with-gtest-cmake-and-doxygen
# http://www.kaizou.org/2014/11/gtest-cmake/
cmake_minimum_required(VERSION 2.8)
project(ThreadTest C CXX)
ADD_SUBDIRECTORY (gtest-1.7.0)
enable_testing()
#set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(GTest REQUIRED)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
if(NOT MSVC)
set(PThreadLib -pthread)
endif()
add_executable(ThreadTest main_test.cpp)
target_link_libraries(ThreadTest ${PThreadLib} ${GTEST_LIBRARIES})
#add_test(ThreadTest ThreadTest)
I want to highlight some things: a few valuable links and
project(ThreadTest C CXX) rather than project(ThreadTest)
and
set(PThreadLib -pthread) rather than set(PThreadLib pthread)
I guess the rest can be managed. It could be a good starting point.
I integrated Google Test framework in my own project and this CMake file is working.
# Google C++ Testing Framework
# https://code.google.com/p/googletest/
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
if(WIN32)
# GTest is static compiled by default
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
endif()
enable_testing()
add_executable(ThreadTest main_test.cpp)
target_link_libraries(ThreadTest ${GTEST_BOTH_LIBRARIES})
CMake warning "Could NOT find Threads" is related to a bug:
CMake failing to detect pthreads due to warnings
All you need to do is link with pthread:
target_link_libraries(BUILD_ARTIFACT pthread)
BUILD_ARTIFACT can be your project, or library name. You should add this line after defining your artifact.
For example, if your build artifact is ThreadTest:
add_executable(ThreadTest main_test.cpp)
target_link_libraries(ThreadTest pthread)
I'm working on a project using the SDL (v1.2.15-7) and CMake (3.2.1). In the *.h files I added the #include <SDL.h> and when I compile it, I have a bunch of errors : undefined reference to SDL_...
I think the mistake comes from the CMakeLists.txt but I really don't know where.
Here's the file content :
CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )
SET( PROJ_NAME "Project" )
SET( PROJ_PATH ${CMAKE_SOURCE_DIR} )
SET( PROJ_OUT_PATH ${CMAKE_BINARY_DIR} )
SET( PROJ_INCLUDES "include" )
FILE( GLOB_RECURSE PROJ_SOURCES src/*cpp test/*cpp doc/*)
FILE( GLOB_RECURSE PROJ_HEADERS ${PROJ_INCLUDES}/${PROJ_NAME}/*.h )
PROJECT( ${PROJ_NAME} )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
FIND_PACKAGE( SDL REQUIRED )
SET( PROJ_LIBRARIES ${SDL_LIBS} )
INCLUDE_DIRECTORIES( ${PROJ_INCLUDES} ${SDL_INCLUDE_DIR} )
ADD_EXECUTABLE( ${PROJ_NAME} ${PROJ_SOURCES} ${PROJ_HEADERS} )
TARGET_LINK_LIBRARIES( ${PROJ_NAME} ${PROJ_LIBRARIES} )
I also tried #include SDL/SDL.h
The error message is coming from the linker, in which case it means you're not linking against the SDL libraries.
The CMake documentation specifies that the FindSDL module defines a variable named SDL_LIBRARY, but you're using SDL_LIBS. So, SET(PROJ_LIBRARIES ${SDL_LIBRARY}) instead.
When using a standard module for finding a package, try browsing the documentation first to take a look at the variables it defines. The names aren't always standard.
Try using SDL_LIBRARY instead of SDL_LIBS
You forgot to link your target to SDL_LIBRARIES in the last line of your CMakeLists.txt.
The linker produces the error, so it is unrelated to your includes.