I am trying to get a basic setup with GLFW and Vulkan for an upcoming project. I was trying to get a simple HelloTriangle Example to work. While the Vulkan library is building normally, the GLFW is throwing a ld: library not found for -lglfw3 on running the program. I am also unsure whether my HelloTriangle example is a working example; it was the most basic example I have to seen to test Vulkan.
Here is my CMakeList.txt:
cmake_minimum_required(VERSION 3.16)
project(OpenGLRun)
set(CMAKE_CXX_STANDARD 14)
set(glfw3_DIR /usr/local/Cellar/glfw/3.3.2/lib/cmake/glfw3)
add_executable(OpenGLRun main.cpp)
find_package(vulkan REQUIRED)
find_package(glm REQUIRED)
find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)
target_link_libraries(OpenGLRun Vulkan::Vulkan)
target_link_libraries(OpenGLRun glm)
target_link_libraries(OpenGLRun OpenGL::GL)
target_link_libraries(OpenGLRun glfw3)
And the main.cpp example code that I was trying to run for proof that everything was working:
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <iostream>
#include <stdexcept>
#include <cstdlib>
const uint32_t WIDTH = 800;
const uint32_t HEIGHT = 600;
class HelloTriangleApplication {
public:
void run() {
initWindow();
initVulkan();
mainLoop();
cleanup();
}
private:
GLFWwindow* window;
void initWindow() {
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
}
private:
void initVulkan() {
}
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
}
void cleanup() {
glfwDestroyWindow(window);
glfwTerminate();
}
};
int main() {
HelloTriangleApplication app;
try {
app.run();
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
And finally, for the future, would you recommend package managers in C++/CMake?
Thanks in advance
The GLFW Build Guide suggests that whether you are compiling and linking GLFW along with your application, or linking an installed GLFW to your application, you can link GLFW to your application using the glfw target (not glfw3). Change the target_link_libraries() command in your CMake to this:
target_link_libraries(OpenGLRun PRIVATE glfw)
Note, you should always provide the scoping argument when using the target-based commands such as this, to tell CMake whether this is a build requirement, a usage requirement, or both.
Related
QT version: 5.12.0
OpenGL version: 4.5 core
Development environment: VS 2017
pro file:
QT += widgets
...
I have already add the glad.c file into my project, and ensure that the glad.h is included at the first place in every file.
But while I compile my project, all the other classes that using OpenGL functions are normal, except the class inherited from QOpenGLWidget.
MappingView.h
#include <glad/glad.h>
...
class MappingView : public QOpenGLWidget {
Q_OBJECT
public:
MappingView(QWidget * parent = nullptr);
~MappingView();
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
...
GLuint m_pointer_texture;
}
MappingView.cpp
MappingView::MappingView(QWidget * parent) : QOpenGLWidget(parent) {
}
MappingView::~MappingView() {
glDeleteTextures(1, &m_pointer_texture);
}
void MappingView::initializeGL() {
// load glad
if (!gladLoadGL()) {
return;
}
glGenTextures(1, &m_pointer_texture);
}
Compile error: C3861, cann't find glDeleteTextures.
When I click to the definition of glDeleteTextures in VS, it will jump to QOpenGLFunctions, but not glad.h. It seems that the OpenGL in QT and glad is conflicting. But my project doesn't use QOpenGLFunctions.
When I try to add a macro in MappingView.h,
#define QT_NO_OPENGL
all OpenGL functions in MappingView can be successfully found in glad.h, but the base class QOpenGLWidget cannot be found instead, which means that the MappingView class cannot be inherited from QOpenGLWidget any more.
I would be very appreciated if somebody could help me to resolve the problem, thanks!
I'm a novice in Qt5, want to make a simple programm with interactive 3D graphics. I create a new Qt Widgets app, following manuals I do QT += opengl in .pro, #include<QtOpenGL> in .h, and that's all. I even don't add any extra code, I click "build project" and get this:
/opt/qtsdk/5.5/gcc/include/QtGui/qopenglext.h:117: ошибка: typedef
'PFNGLDRAWRANGEELEMENTSPROC' is initialized (use decltype instead)
typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode,
GLuint start, GLuint end, GLsizei count, GLenum type, const void
*indices); 'GLenum' was not declared in this scope 'GLuint' was not declared in this scope 'GLsizei' was not declared in this scope
'GLenum' was not declared in this scope expected primary-expression
before 'const' typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC)
(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type,
const void *indices); typedef 'PFNGLTEXIMAGE3DPROC' is initialized
(use decltype instead) typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC)
(GLenum target, GLint level, GLint internalformat, GLsizei width,
GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum
type, const void *pixels);
and same on and on till I stop building as I get the 8140th error, which isn't the last. :\
Please, help!! Tried everything, can't take it anymore
I installed Qt5 (lib and IDE together) by online-installation, then tried to fix them:
$ apt-get install libgl1-mesa-dev
$ sudo aptitude install mesa-common-dev
$ sudo apt-get install build-essential libfontconfig1
etc. Tried everything, that managed to find regarding my problem (though google says nothig useful solving exactly my problem)
OS: Linux Mint 17.1 Cinnamon 32bit
Video card: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (Total crap. Maybe, that's an issue?)
OpenGL version: 3.0 Mesa 10.1.3 (Does QtOpengl use a default Оpengl, preinstalled on my laptop, or uses its own Opengl? Though, how do versions of Opengl and Qt correlate? Would Qt4-5 even work witn an old Opengl version?)
Qt version: 4.8.6 (At least console says so, but I'm not shure that projects aren't built with Qt5 libs. How can I explicitly specify the version I need to build the project by the way?)
Auto-detected Qt version: Desktop Qt 5.5.1 GCC 32bit
QMake version: 2.01a
Auto-detected compiler: GCC; debugger: GDB
Need your help very much! Thanks
The only code I have:
That's mainscene.h:
#ifndef MAINSCENE_H
#define MAINSCENE_H
#include <QMainWindow>
#include<QtOpenGL>
#include<QGLWidget>
class MainScene : public QMainWindow
{
protected:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
public:
Scene3D(QWidget* parent = 0);
};
#endif // MAINSCENE_H
That's the SimpleOpengl.pro:
QT += core gui
QT += opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SimpleOpengl
TEMPLATE = app
SOURCES += main.cpp
mainscene.cpp
HEADERS += mainscene.h
That's the main.cpp:
#include "mainscene.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainScene w;
w.show();
return a.exec();
}
(It's all wrong, isn't it?..)
I just installed CLion today on my new Linux environment and I decided to try to make a simple socket server. I eventually want to create a socket server in C++ (because I already made tons in C#, Java, Python, PHP, Node.js...).
I got the following code:
//
// Created by josh on 10-10-16.
//
#ifndef RANDOMPROGRAM_TEST_H
#define RANDOMPROGRAM_TEST_H
#include <iostream>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
using namespace boost::asio::ip;
class test {
private:
boost::asio::io_service io_service;
tcp::acceptor acceptor;
tcp::socket socket;
test() {
this->acceptor = tcp::acceptor(this->io_service, tcp::endpoint(tcp::v4(), 30000));
this->socket = tcp::socket(io_service);
acceptor.async_accept(this->socket, boost::bind(&this->handle_accept, this, this->socket, NULL));
}
void handle_accept(tcp::socket* client, const boost::system::error_code& error) {
}
};
#endif //RANDOMPROGRAM_TEST_H
In my main .cpp file (which gets called when the program is executed):
#include "test.h"
int main() {
test t();
return 0;
}
Finally, my CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(Randomshitprogram)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Boost 1.62.0 COMPONENTS system filesystem REQUIRED)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
set(SOURCE_FILES main.cpp test.h)
add_executable(Randomshitprogram ${SOURCE_FILES})
Now, when I try to execute the program, it gives the following error, together with possibly a ton of errors:
No matching function for call to ‘boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>::basic_socket_acceptor()’
The log:
http://pastebin.com/a09FvuTk
when I try to execute
you mean compile, right? That's a compile error, not a runtime one.
No matching function for call to 'boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>::basic_socket_acceptor()'
The constructor for boost::asio::basic_socket_acceptor is documented here. There is no default constructor, which is what your compiler is telling you.
You're invoking (or trying to) the default constructor here:
test() /* here */ {
this->acceptor = tcp::acceptor(this->io_service, tcp::endpoint(tcp::v4(), 30000));
this->socket = tcp::socket(io_service);
acceptor.async_accept(this->socket, boost::bind(&this->handle_accept, this, this->socket, NULL));
}
where there is no initializer list. Any data members of test must be constructed before the body of your constructor.
Your constructor should look something like this:
test()
: acceptor(io_service, tcp::endpoint(tcp::v4(), 30000))
, socket(io_service)
{
acceptor.async_accept(socket, boost::bind(&this->handle_accept, this, this->socket, NULL));
}
Ok, since I'm working on a private project using ROS Framework, my motivation was raised by the new C++14 auto lambda feature (see this link for a better explanation).
the problem I am facing is that ROS framework is sticking to the old days C++03 for it's compilation. So, how can I enable C++14 compilation support and how can I use the lambda functions ?
Here's a simple nodes for testing with the lambda function (in the subscriber node) :
publisher :
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <std_msgs/Int8.h>
#include <sstream>
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher string_pub = n.advertise<std_msgs::String>("chatter_string", 1000);
ros::Publisher int_pub = n.advertise<std_msgs::Int8>("chatter_int", 1000);
ros::Rate loop_rate(10);
int count = 0;
while (ros::ok())
{
std_msgs::String str_msg;
std::stringstream ss;
ss << "hello world ";
str_msg.data = ss.str();
std_msgs::Int8 int_msg;
int_msg.data = count;
string_pub.publish(str_msg);
int_pub.publish(int_msg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
subscriber :
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <std_msgs/Int8.h>
//generic lambda to add two variables
auto func = [](auto input) { return input + input; };
void StringCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("I heard: [%s]", func(msg->data).c_str());
}
void IntCallback(const std_msgs::Int8::ConstPtr& msg)
{
int result = msg->data;
ROS_INFO("I heard: [%d]", func(result));
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber string_sub = n.subscribe("chatter_string", 1000, StringCallback);
ros::Subscriber int_sub = n.subscribe("chatter_int", 1000, IntCallback);
ros::spin();
return 0;
}
CMakeLists :
cmake_minimum_required(VERSION 2.8.3)
project(tutocpp14)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
catkin_package()
include_directories( ${catkin_INCLUDE_DIRS} include )
add_executable(listener src/listener.cpp)
add_executable(publisher src/publisher.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
target_link_libraries(publisher ${catkin_LIBRARIES})
Making the package after this configuration throw me the following error :
tutocpp14/src/listener.cpp:10:43: error: ‘func’ was not declared in this scope
ROS_INFO("I heard: [%s]", func(msg->data).c_str());
It turned out that I can add the C++14 to ROS for my package compilation. Although this is not advised for publishing the packages.
Use of C++11/C++14 features and filesystem/networking/etc... TS's (Technical Specifications) is allowed if they are checked for at configure time and equivalent functionality can be provided with the extra compiler features. Support for C++11 is now a compiler requirement, but the API of the packages included in desktop-full will not use any C++11-specific feature. External packages are encouraged to follow this guideline.
But, still that I am not intending to publish my work for now, so, I can get myself the permit to do so.
To get C++14 support for a ROS package, I have to set the -std=c++14 flag by adding the following lines in my CMakelists.txt file :
# check c++14 / c++0x
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "-std=c++14")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "-std=c++0x")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
endif()
this will check the existence of C++14 in the compiler and throw an error if not. Now, it works like a charm.
Hope that helps. Cheers.
I recently tried writing animated wallpaper plugins for KDE4. When I switch among them, the animations get jumbled. That is, the previous animation doesn't stop, and the previous frames and the current frames get mixed together. I embed the frames into each program as image resources. Then I write code like the following for each wallpaper. Can anyone tell me what I'm missing (or if it's just a KDE bug)?
dancingcoffee.h
#ifndef DANCINGCOFFEE_H
#define DANCINGCOFFEE_H
#include <Plasma/Wallpaper>
#include <QPainter>
#include <QTimer>
class DancingCoffee : public Plasma::Wallpaper
{
Q_OBJECT
public:
DancingCoffee(QObject *parent, const QVariantList& args);
void paint(QPainter *painter, const QRectF &exposedRect);
private slots:
void updateBackground();
private:
const int m_frames;
const int m_interval;
int m_frame_number;
QTimer m_timer;
};
#endif // DANCINGCOFFEE_H
dancingcoffee.cpp
#include "dancingcoffee.h"
#include <QImage>
K_EXPORT_PLASMA_WALLPAPER(coffee, DancingCoffee)
DancingCoffee::DancingCoffee(QObject *parent, const QVariantList &args) :
Plasma::Wallpaper(parent, args),
m_frames(2),
m_interval(1000 / m_frames)
{
m_frame_number = 0;
m_timer.setSingleShot(true);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateBackground()));
m_timer.start(m_interval);
}
void DancingCoffee::paint(QPainter *painter, const QRectF &exposedRect)
{
QString name = QString(":/images/frame-%1.png").arg(m_frame_number);
QImage image(name);
painter->drawImage(exposedRect, image);
}
void DancingCoffee::updateBackground()
{
++m_frame_number;
m_frame_number %= m_frames;
m_timer.start(m_interval);
emit update(boundingRect());
}
CMakeLists.txt
set(CMAKE_INSTALL_PREFIX /usr)
project(plasma-wallpaper-coffee)
cmake_minimum_required(VERSION 2.8)
find_package(KDE4 REQUIRED)
find_package(KDE4Workspace REQUIRED)
include(KDE4Defaults)
add_definitions(${KDE4_DEFINITIONS})
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})
set(TARGET plasma_wallpaper_coffee)
set(SRC_LIST dancingcoffee.cpp)
qt4_add_resources(RCC_LIST dancingcoffee.qrc)
kde4_add_plugin(${TARGET} ${SRC_LIST} ${RCC_LIST})
target_link_libraries(${TARGET} ${KDE4_PLASMA_LIBS})
install(TARGETS ${TARGET} DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES plasma-wallpaper-coffee.desktop DESTINATION ${SERVICES_INSTALL_DIR})
plasma-wallpaper-coffee.desktop
[Desktop Entry]
Name=Coffee
Type=Service
Icon=image-jpeg
ServiceTypes=Plasma/Wallpaper
X-KDE-Library=plasma_wallpaper_coffee
X-KDE-PluginInfo-Author=Chris French
X-KDE-PluginInfo-Email=unclechromedome#gmail.com
X-KDE-PluginInfo-Name=coffee
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
And voila! Animated wallpaper on my desktop. But the wallpapers don't play well together. I have to kill the desktop and restart it when I switch wallpapers, and sometimes that doesn't even work. Sometimes I have to do a hard reboot. It's a pain for me, and unacceptable if I ever distribute the wallpapers.