Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'make_unique' is not a member of 'std'

Tags:

c++

g++

c++17

cmake

I'm using g++-9 and c++17 on Linux Mint 19.2. The compiler is literally telling me to include <memory> adjacent to where I'm already including it:

/home/luke/workspace/crab/Src/Brain/EpisodicMemory.cpp:2:1: note: ‘std::make_unique’ is defined in header ‘<memory>’; did you forget to ‘#include <memory>’?
    1 | #include "EpisodicMemory.h"
  +++ |+#include <memory>
    2 | #include <memory>

I can produce the error with this minimal example:

#include <memory>
int main(int argc, char** argv) {
    std::unique_ptr<int> test = std::make_unique<int>(4);
    return 0;
}

Really don't know what's going on.

Here is my CMakeLists.txt (since you don't believe I'm using c++17):

cmake_minimum_required(VERSION 3.10)
project(crab)
find_package(Qt5Widgets)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -Wall -O0 -g -fsanitize=address -std=c++17 -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
include_directories(${Qt5Widgets_INCLUDE_DIRS})
#file(GLOB BRAIN_FILES Brain/*.cpp Brain/*.h)
#add_executable(crab ${BRAIN_FILES} main.cpp)
add_executable(crab main.cpp)
target_link_libraries(crab Qt5::Widgets)

I think linking Qt might be changing my compiler settings but I don't know why that would happen

like image 211
Luke Avatar asked Nov 03 '25 02:11

Luke


1 Answers

I fixed it by replacing -std=c++17 with set(CMAKE_CXX_STANDARD 17)

like image 188
Luke Avatar answered Nov 05 '25 16:11

Luke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!