在CMakeLists.txt文件中设定
// An highlighted block
set(CMAKE_CXX_FLAGS "-no-pie")
set(CMAKE_C_FLAGS "-no-pie")
例程
main.cpp
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char **argv) {
ofstream ofs("test.txt");
ofs<<"hello world!"<<endl;
ofs.close();
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(demo0)
set(CMAKE_CXX_FLAGS "-no-pie")
set(CMAKE_C_FLAGS "-no-pie")
add_executable(demo0 main.cpp)