error: ‘to_string’ is not a member of ‘std’

1.Linux 下两个makefile编译同一个源文件,两个makefile编译同一个源文件,第一个makefile可以通过,第二个makefile就会报错error: ‘to_string’ is not a member of ‘std’

2.makefile文件
(1)源码

if(handle_status == 0) {
    send_str = "{\"status\":\"ok\", \"errorcode\":" + std::to_string(handle_status) + "}";
} else {
    send_str = "{\"status\":\"error\", \"errorcode\":" + std::to_string(handle_status) + "}";
}

(2)第一个makefile

OBJS = broadcast.o nvme_gpu_handle.o udp_server.o
CC = g++
CFLAGS = -Wall -g -std=c++11

psme_client : $(OBJS)
    $(CC) $(OBJS) -o psme_client

udp_server.o : udp_server.cpp  udp_server.hpp
    $(CC) $(CFLAGS) -c udp_server.cpp -o udp_server.o

broadcast.o : broadcast.cpp broadcast.hpp
    $(CC) $(CFLAGS) -c broadcast.cpp -o broadcast.o

nvme_gpu_handle.o : nvme_gpu_handle.cpp nvme_gpu_handle.hpp
    $(CC) $(CFLAGS) -c nvme_gpu_handle.cpp -o nvme_gpu_handle.o

clean :
    rm -rf *.o
    rm -rf psme_client

(3)第二个makefile

CC := g++
CFLAGS := -std=c++11 -g -Wall -O3 
Target := psme_client
Source := $(wildcard ./*.cpp)
ndir := $(notdir $(Source))
Objs := $(patsubst %.cpp,%.o,$(Source))

.PHONY: all clean

$(Target) : $(Objs)
    $(CC) $(CFLAGS) -o $(Target) $(Objs)
    @ echo "make $(Target) down!"    

all:
    $(Target)     
    
clean:
    rm -rf $(Objs)
    @ echo "clean down"

3.错误图片描述
error: ‘to_string’ is not a member of ‘std’
4.截图
图片描述

5.找过的解决方法
https://stackoverflow.com/que...
还有其他的,都没有解决,求大神相助!

阅读 9.2k
2 个回答

你用@echo把第二个 Makefile 生成的完整 编译命令 打印出来看看不就知道了。

新手上路,请多包涵

g++ version,第二个makefile输出日志完整贴出来看看

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题