Quantcast
Viewing all articles
Browse latest Browse all 22006

Is there a way to force multiply defined symbols using GCC/Clang on Linux?

I am working with two separate libraries (PLCIO and azure-iot-sdk-c) on a project. This project is being developed primarily on Windows using Visual Studio, but needs to run on Linux in production. I'm currently using a Ubuntu box to simulate production. When compiling the program in Visual Studio on Windows I get the linker errors LNK2005 and LNK1169. I solved this problem by using the /FORCE:MULTIPLE linker option in Visual Studio. Our app compiles and runs as expected on Windows.

Image may be NSFW.
Clik here to view.
Visual Studio Linker Errors Screenshot

When I port the code and libraries over to my Linux test box, I am using cmake to build and link everything. The project builds and links properly, but when it runs I get an unexpected segmentation fault. I've narrowed it down to an interaction between the two libraries by creating stub programs using one library at a time and confirming that they work as expected. It's only when I put both libraries together that I run into problems. I think it is a fair assumption that the same multiply defined symbols error is causing this seg fault on Linux, it just isn't caught during compile for some reason.

I have tried a whole host of compile and linker flags (using both GCC and Clang) to build this project to try and fix this issue. I have tried -fvisibility=hidden-shared-nostdlib. I found -symbolic in the GCC documentation, but am getting a "option not recognized" error when I try to use it. I was originally statically linking to pre-built libraries, but have also tried both dynamically linking and also building the azure-iot-sdk myself with the rest of my code. I am getting the same result every time.

Essentially my question comes down to, is there any equivalent of /FORCE:MULTIPLE for a Linux tool chain (GCC, Clang, I don't care) that can fix this problem. Or, is there some alternative solution that I have somehow missed in my hours and hours of Googling and troubleshooting?


Viewing all articles
Browse latest Browse all 22006

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>