[英]Compiled C++ build doesn't output nor provide error
I'm using cmake and mingw32-make to build my C++ SDL2 project called Something
.我正在使用 cmake 和 mingw32-make 构建我的 C++ SDL2 项目,名为
Something
。
After I did cmake.
在我做了
cmake.
it generated few folders and files, where I went inside the build folder.它生成了几个文件夹和文件,我进入了 build 文件夹。 It had a make file, so I used
make
in that directory.它有一个make文件,所以我在那个目录中使用了
make
。
Then it generated my executable which should be something.exe
.然后它生成了我的可执行文件,它应该是
something.exe
。 It did, but when I try to run the executable it provides no errors or output.确实如此,但是当我尝试运行可执行文件时,它没有提供任何错误或 output。 When I try to compile without including
SDL.h
and commenting the sdl code, it outputs Initialized
which should appear even with including SDl.h
.当我尝试在不包含
SDL.h
并注释 sdl 代码的情况下进行编译时,它会输出Initialized
,即使包含SDl.h
出现。
This is my project directory这是我的项目目录
Something
|
|
|---- SDL2
| |
| |---- include
| |
| |---- lib
|
---- src
| |
| |---- something.cpp
|
|
|---- CMakeLists.txt
This is my cmake file这是我的 cmake 文件
# cmake version to be used
cmake_minimum_required( VERSION 3.8.0 )
project(something VERSION 1.0.0)
set(SDL2_DIR "${CMAKE_SOURCE_DIR}/SDL2/")
set(SDL2_INCLUDE_DIRS "${SDL2_DIR}/include")
# Support both 32 and 64 bit builds
if (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
set(SDL2_LIBRARIES "${SDL2_DIR}/lib/x64/SDL2main.lib;${SDL2_DIR}/lib/x64/SDL2.lib")
else ()
set(SDL2_LIBRARIES "${SDL2_DIR}/lib/x86/SDL2main.lib;${SDL2_DIR}/lib/x86/SDL2.lib")
endif ()
# link dependencies
include_directories(${SDL2_INCLUDE_DIRS})
link_directories(${SDL2_LIBRARIES})
# link dependencies
include_directories(${SDL2_INCLUDE_DIRS})
link_directories(${SDL2_LIBRARIES})
# Project files and linking
set(SOURCES src/something.cpp)
add_executable(${PROJECT_NAME} src/something.cpp)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
And finally this is my src/something.cpp
最后这是我的
src/something.cpp
#include <iostream>
#include <SDL.h>
int main(int agrc, char* agrs[]){
std::cout << "Initialized!!" << std::endl;
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
if ( SDL_Init(SDL_INIT_EVERYTHING) != 0 ){
std::cout << "Error : " << SDL_GetError() << std::endl;
return -1;
}
window = SDL_CreateWindow("Something", 50, 50, 700, 500, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_Delay(1000);
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit();
return 0;
}
Must not forget to put the .dll
(dynamic link libraries) in the same directory as the executable in order for the executable to work一定不要忘记将
.dll
(动态链接库)与可执行文件放在同一目录中,以使可执行文件工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.