CLion, MinGW and SDL2: Process finished with exit code -1073741515 (0xC0000135) - c++

I am trying to add SDL2 to my CLion project. I found this guide and tried to follow it while including only SDL2. Everything compiles, but when I start my app I get "Process finished with exit code -1073741515 (0xC0000135)".
In my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.15)
project(Test)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "-lmingw32 -static-libgcc -static-libstdc++")
set(SDL2_PATH "C:/CPP/libs/SDL2-2.0.10/x86_64-w64-mingw32")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "C:/CPP/libs/CMakeModules")
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
if (${SDL2_FOUND})
message(VERBOSE, "sdl found!")
else ()
message(FATAL_ERROR, "sdl not found")
endif ()
message(VERBOSE, ${SDL2_INCLUDE_DIR})
message(VERBOSE, ${SDL2_LIBRARY})
add_executable(Test src/main.cpp)
target_link_libraries(Test ${SDL2_LIBRARY})
main.cpp:
#include <SDL.h>
#include <cstdio>
int main(int argc, char *args[]) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
}
SDL_Quit();
return 0;
}
I am using CLion 2019.3.2 with bundled CMake, latest MinGW build (x86_64-8.1.0-win32-seh-rt_v6-rev0) and latest SDL2 (2.0.10).
CMake output also looks ok:
VERBOSE,sdl found!
VERBOSE,C:/CPP/libs/SDL2-2.0.10/x86_64-w64-mingw32/include/SDL2
VERBOSE,mingw32-mwindowsC:/CPP/libs/SDL2-2.0.10/x86_64-w64-mingw32/lib/libSDL2main.aC:/CPP/libs/SDL2-2.0.10/x86_64-w64-mingw32/lib/libSDL2.dll.a-lpthread

if you are using visual studio toolchains in CLion:
You need to paste in folder cmake-build-debug or cmake-build-release the files .dll, but no only SDL2_image.dll, all files from folder lib/x86
SDL2_image-devel-2.0.5-VC.zip

My CMakeLists.txt seems different from yours.
Here are my configurations, Hope can help you.
cmake_minimum_required(VERSION 3.15)
project(cppSDL)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLIGS "${CMAKE_CXX_FLAGS} -std=c++17 -lmingw32")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib/x86)
set(SOURCE_FILES SDLtutorial.cpp)
add_executable(SDLtutorial ${SOURCE_FILES})
target_link_libraries(SDLtutorial SDL2main SDL2 SDL2_ttf SDL2_image)

Related

cLion + Qt5 - exit code -1073741515 (0xC0000135)

I'm trying to run simple test using QT5 and cLion but I run in to the exit code wall... Here is my envi :
cLion 2017.2
minGw 5.0 < according to cLion
cMake 3.8.2
Qt 5.9.0
CMakeList.txt
cmake_minimum_required(VERSION 3.8)
project(testWindotQt)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp )
add_executable(testWindotQt ${SOURCE_FILES})
if (WIN32)
# If you compile on windows replace path to your Qt folder
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.9\\mingw53_32")#\\lib\\cmake")
endif()
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
qt5_use_modules(testWindotQt Core Widgets Gui)
target_link_libraries(testWindotQt Qt5::Widgets Qt5::Core Qt5::Gui)
main.cpp
#include <iostream>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
int main(int argc, char *argv[])
{
std::cout << "Hello, World!" << std::endl;
QApplication a(argc, argv);
QLabel *label = new QLabel("HeyYou");
label->show();
return a.exec();
}
Execution >
Process finished with exit code -1073741515 (0xC0000135)
Can any1 help me out with this error please?
Regards
Dariusz
Have a look at this post: Setting up Qt for CLion
Basically, you have to add C:\QT\5.x\mingwxx_32\bin to your PATH environment variable.

cmake: undefined reference to any pcap functions

I want to use pcap in my Clion project on linux.
I installed libpcap-dev:
sudo apt-get install libpcap-dev
But then I try to compile any file, containing pcap functions like:
#include <stdio.h>
#include <pcap.h>
int main(int argc, char *argv[])
{
char *dev, errbuf[PCAP_ERRBUF_SIZE];
dev = pcap_lookupdev(errbuf);
if (dev == NULL) {
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
return(2);
}
printf("Device: %s\n", dev);
return(0);
}
I have cmake errors:
CMakeFiles/main.cpp.o: In function `main':
/main.cpp:8: undefined reference to `pcap_lookupdev'
I have not used cmake before. Cmake file:
cmake_minimum_required(VERSION 3.7)
project(mypr)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(mypr ${SOURCE_FILES})
You should include and use a FindPCAP.cmake file to your CMakeLists.txt. Here is one: https://github.com/bro/cmake/blob/master/FindPCAP.cmake
Put FindPCAP.cmake in your project's source directory and try changing your CMakeLists.txt to:
cmake_minimum_required(VERSION 3.7)
project(mypr)
set(CMAKE_CXX_STANDARD 11)
include(FindPCAP.cmake)
set(SOURCE_FILES main.cpp)
add_executable(mypr ${SOURCE_FILES})
target_link_libraries(mypr ${PCAP_LIBRARY})
I think you can also use CMAKE_MODULE_PATH (assume FindPCAP.cmake is in your project's source directory):
cmake_minimum_required(VERSION 3.7)
project(mypr)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/")
find_package(PCAP REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(mypr ${SOURCE_FILES})
target_link_libraries(mypr ${PCAP_LIBRARY})
I have encounted with a problem similar to this, when I tried to complied with libpcap by ros catkin_make
CMakeFiles/decode_pcap.dir/src/decode_pcap.cpp.o:在函数‘main’中:
decode_pcap.cpp:(.text+0x130):对‘pcap_open_live’未定义的引用
decode_pcap.cpp:(.text+0x1b3):对‘pcap_next’未定义的引用
decode_pcap.cpp:(.text+0x2a4):对‘pcap_loop’未定义的引用
decode_pcap.cpp:(.text+0x2e6):对‘pcap_close’未定义的引用
decode_pcap.cpp:(.text+0x2ff):对‘pcap_close’未定义的引用
collect2: error: ld returned 1 exit status
at last, I added the absolute path to "libpcap.so" by link_libraries() in CMakeLists.txt,like the below
link_libraries(/usr/lib/x86_64-linux-gnu/libpcap.so.0.8)

How do I connect static libs in CLion with CMake?

I want to use OpenGL 4.5 and freeglut in my project. I've got compiled freeglut library (include folder, .dll and .lib). Here's CMakeLists.txt I've got so far:
cmake_minimum_required(VERSION 3.7)
project(DuperTest)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include})
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)
add_executable(DuperTest ${SOURCE_FILES})
target_link_libraries(DuperTest ${OPENGL_LIBRARIES})
target_link_libraries(DuperTest ${CMAKE_SOURCE_DIR}/lib/freeglut.lib)
But still no luck #include <gl.h> and #include <GL/freeglut.h> still not working. What should I do?

How to add allegro Library in Clion and CMake?

I am trying to compile my game project using Clion IDE but I have a problem when porting allegro 5. I get this error:
main.cpp:2:10: fatal error: 'allegro/allegro.h' file not found
#include <allegro/allegro.h>
My CMakeLists is:
cmake_minimum_required(VERSION 3.5)
project(testAllegro)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(testAllegro ${SOURCE_FILES})
INCLUDE_DIRECTORIES( /usr/local/include )
LINK_DIRECTORIES( /usr/local/lib )
file(GLOB LIBRARIES "/usr/local/Cellar/allegro/5.2.1.1_1/lib/*.dylib")
message("LIBRARIES = ${LIBRARIES}")
TARGET_LINK_LIBRARIES(testAllegro ${LIBRARIES})
Just I want to ask how can I add external Library allegro to Clion?
when you install allegro using homebrew link
use this cmake to compile clion project
cmake_minimum_required(VERSION 3.5)
project(testAllegro)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(testAllegro ${SOURCE_FILES})
INCLUDE_DIRECTORIES( /usr/local/Cellar/allegro/5.2.1.1_1/include )
LINK_DIRECTORIES( /usr/local/Cellar/allegro/5.2.1.1_1/lib )
file(GLOB LIBRARIES "/usr/local/Cellar/allegro/5.2.1.1_1/lib/*.dylib")
message("LIBRARIES = ${LIBRARIES}")
TARGET_LINK_LIBRARIES(testAllegro ${LIBRARIES})

QGLViewer simpleViewer example built with cmake not running

I'm trying to familiarize with QGLViewer (http://libqglviewer.com/) so I installed it (on Ubuntu 14.04) and I'm trying to run the simpleViewer (which is a provided example). Now, the code can be built using qmake, but I want to compile the code with cmake so I wrote the following CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
PROJECT(simple_viewer)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
FIND_PACKAGE(OpenGL REQUIRED)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE})
FIND_PACKAGE(QGLViewer REQUIRED)
INCLUDE_DIRECTORIES(${QGLVIEWER_INCLUDE_DIR})
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(${QT_INCLUDES})
ADD_EXECUTABLE(${PROJECT_NAME} main.cpp simpleViewer.cpp)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARIES} ${QGLVIEWER_LIBRARY})
I'm able to build the project but when I launch the executable this is the error I get:
dede#dede-P35V2:~/src/simple_viewer/build$ ./simple_viewer
*** Error in `./simple_viewer': realloc(): invalid pointer: 0x00007f64d34df840 *** Aborted
I'd be glad if someone could explain me what's wrong!
Thanks!
worked this way:
cmake_minimum_required(VERSION 2.6)
PROJECT(simple_viewer)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
FIND_PACKAGE(OpenGL REQUIRED)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE})
FIND_PACKAGE(QGLViewer REQUIRED)
INCLUDE_DIRECTORIES(${QGLVIEWER_INCLUDE_DIR})
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
INCLUDE_DIRECTORIES(${QT_INCLUDES})
ADD_EXECUTABLE(${PROJECT_NAME} main.cpp simpleViewer.cpp)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
${QGLVIEWER_LIBRARY}
${QT_QTXML_LIBRARY}
${QT_QTOPENGL_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTCORE_LIBRARY}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
)