简体   繁体   English

跨操作系统的编译器行为不一致(使用 ubuntu docker 容器的 Mac OS/Windows)(“无符号”的多重定义)

[英]Compiler behavior inconsistent across Operating System(Mac OS/Windows using ubuntu docker container) (multiple definition of 'no symbol')

I am trying to compile a c++ program I wrote within a docker container in MacOS, but I keep getting inconsistent compiler behavior.我正在尝试编译我在 MacOS 中的 docker 容器中编写的 c++ 程序,但我一直得到不一致的编译器行为。 My program compiles and runs in Windows with the docker container(with exact same settings) expectedly, but whenever I try to compile in the docker container within Mac it gives me this error.我的程序按预期使用 docker 容器(具有完全相同的设置)在 Windows 中编译和运行,但是每当我尝试在 Mac 中的 docker 容器中编译时,它都会给我这个错误。 Sometimes the program will compile and run, but other times it will compile but it will not run and instead give me a segmentation fault.有时程序会编译并运行,但有时它会编译但不会运行,而是给我一个分段错误。 Most often, it will fail to compile with a message attached below.大多数情况下,编译失败,并附上一条消息。 I have tried creating new docker image, but it did not seem to work.我尝试创建新的 docker 镜像,但似乎没有用。 Any help would be greatly appreciated.任何帮助将不胜感激。

Edit: removed the image and formatted as a code.编辑:删除图像并格式化为代码。 The compiler error shows for all C++ program that I try to compile in this environment.对于我尝试在此环境中编译的所有 C++ 程序,都会显示编译器错误。

Edit2: included the docker file settings. 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 file settings are as follows: 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"

I was having the same problem as you.我和你有同样的问题。

It seems that Docker 2.4.0.0 uses gRPC-FUSE for file sharing by default. Docker 2.4.0.0 似乎默认使用 gRPC-FUSE 进行文件共享。 Somehow this was messing up with my build system (cmake / make).不知何故,这弄乱了我的构建系统(cmake / make)。

I just switched back to osxfs, by going to Preferences > General and disable gRPC-FUSE.我刚刚切换回 osxfs,转到 Preferences > General 并禁用 gRPC-FUSE。

This seems (at least for now) to have solved the problem for me.这似乎(至少现在)已经为我解决了这个问题。 Could you give a try and post an update if it also have the same effect in your case?如果它在您的情况下也有相同的效果,您可以尝试并发布更新吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM