简体   繁体   English

编译的 C++ 构建不 output 也不提供错误

[英]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.

相关问题 错误 c2338 C++ 标准不提供此类型的散列 - error c2338 C++ Standard doesn't provide a hash for this type 临时的C ++地址不会导致生成错误 - C++ Address of Temporary Doesn't Cause a Build Error C++ 程序编译没有问题但不运行 - C++ program compiled without problems but doesn't run C ++标准不提供此类型的哈希 - The C++ Standard doesn`t provide a hash for this type C ++ Fstream输出不起作用 - C++ Fstream Output doesn't work 将MSVS 2010项目转换为MSVS 2012 RC但收到错误“C ++标准不提供此类型的哈希值” - Converting MSVS 2010 project to MSVS 2012 RC but get error “The C++ standard doesn't provide a hash for this type” 双击编译的C ++ Unix可执行文件无法打开现有文件以从中读取信息 - Double Clicked Compiled C++ Unix Executable Doesn't Open Existing File to Read Information From 没有经过GCC优化就编译的简单C ++程序不会产生预期的结果 - Simple C++ Program Compiled without Optimization by GCC doesn't Generate Expected Results 使用VS2008编译的C ++应用程序无法在其他计算机上运行 - A C++ Application Compiled With VS2008 Doesn't Run In Other Computer gdb 在 c++ 二进制编译的 `-g3` 中无法识别 `typedef` 或 `using` - gdb doesn't recognize `typedef` or `using` in c++ binary compiled `-g3`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM