我正在尝试编译我在MacOS中的docker容器中编写的c++程序,但我总是得到不一致的编译器行为。我的程序使用docker容器(使用完全相同的设置)在Windows中编译和运行,但每当我试图在Mac的docker容器中编译时,它都会给我这个错误。有时程序会编译并运行,但有时它会编译,但不会运行,而是会给我一个分段错误。大多数情况下,它将无法编译,因为下面附加了一条消息。我尝试创建新的docker镜像,但似乎不起作用。任何帮助都将不胜感激。
编辑:删除图像并将其格式化为代码。对于我试图在这个环境中编译的所有C++程序,编译器错误都会显示出来。
Edit2:包含docker文件设置。
root@b756b8b2e26b:~/p2# make
[CP] solutions/client.exe --> obj64/client.exe
[CXX] server/server.cc --> obj64/server.o
[CXX] server/server_storage.cc --> obj64/server_storage.o
[CXX] common/pool.cc --> obj64/pool.o
[LD] obj64/server.o obj64/server_storage.o obj64/pool.o ofiles/crypto.o ofiles/err.o ofiles/file.o ofiles/net.o ofiles/vec.o ofiles/server_args.o ofiles/server_commands.o ofiles/server_parsing.o --> obj64/server.exe
/usr/bin/ld: warning: size of symbol `' changed from 7 in obj64/server_storage.o to 82 in obj64/server_storage.o
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0xb10): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0xb70): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0xef0): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x1180): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x1560): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x1970): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x2370): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x2380): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x2760): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x2b50): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x2fd0): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x3b10): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x40b0): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x4630): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x5fd0): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: obj64/server_storage.o: in function `no symbol':
:(.text+0x5fd0): multiple definition of `no symbol'; obj64/server_storage.o::(.text+0xb10): first defined here
/usr/bin/ld: error in obj64/server_storage.o(.eh_frame); no .eh_frame_hdr table will be created
/usr/bin/ld: obj64/server.o: in function `main.cold':
/root/p2/server/server.cc:43: undefined reference to `Storage::~Storage()'
/usr/bin/ld: obj64/server.o: in function `main':
/root/p2/server/server.cc:43: undefined reference to `Storage::Storage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long)'
/usr/bin/ld: /root/p2/server/server.cc:44: undefined reference to `Storage::load()'
/usr/bin/ld: /root/p2/server/server.cc:63: undefined reference to `Storage::shutdown()'
/usr/bin/ld: /root/p2/server/server.cc:43: undefined reference to `Storage::~Storage()'
/usr/bin/ld: /root/p2/server/server.cc:45: undefined reference to `Storage::~Storage()'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_all(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0xd46): undefined reference to `Storage::get_all_users(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_set(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0xf99): undefined reference to `Storage::set_user_data(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&)'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_get(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0x11ce): undefined reference to `Storage::get_user_data(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_reg(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0x13be): undefined reference to `Storage::add_user(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_bye(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0x153e): undefined reference to `Storage::auth(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_sav(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0x169e): undefined reference to `Storage::auth(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: (.text+0x16ad): undefined reference to `Storage::persist()'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_kva(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0x1836): undefined reference to `Storage::kv_all(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_kvi(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0x1a99): undefined reference to `Storage::kv_insert(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&)'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_kvu(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0x1cb9): undefined reference to `Storage::kv_upsert(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&)'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_kvg(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0x1e4e): undefined reference to `Storage::kv_get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ofiles/server_commands.o: in function `server_cmd_kvd(int, Storage&, evp_cipher_ctx_st*, std::vector<unsigned char, std::allocator<unsigned char> > const&)':
(.text+0x2014): undefined reference to `Storage::kv_delete(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:82: obj64/server.exe] Error 1
docker文件设置如下:
#initialize repos and upgrade the base system
RUN apt-get update -y
RUN apt-get upgrade -y
#Install additional software needed for development
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y git man curl build-essential screen gdb libssl-dev psmisc valgrind
# Install Python.
RUN apt-get update && apt-get install -y --no-install-recommends \
python3.5 \
python3-pip \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
#Change the working directory:
WORKDIR "/root"
发布于 2020-11-02 06:35:01
我和你也有同样的问题。
看起来Docker 2.4.0.0默认使用gRPC-FUSE进行文件共享。不知何故,这搞乱了我的构建系统(cmake / make)。
我刚刚切换回osxfs,进入Preferences > General并禁用gRPC-FUSE。
这似乎(至少现在)为我解决了这个问题。如果在你的案例中也有同样的效果,你能尝试一下并发布一个更新吗?
https://stackoverflow.com/questions/64327265
复制相似问题