简体   繁体   中英

Creating an import library for an executable on Linux

I'm looking for a way to unit test my a C++ application linked into an executable. I'm using googletest and I need to link the test executable to the binary under test in order to test that binary. The binary under test is an executable in my case. On Windows I can create an import library for the tested executable and link the test executable with it. As long as I don't export the main function from the tested binary, it works fine. However on Linux I'm not able to do this. When linking directly with the tested executable, linkage fails since there are two main functions, one in the tested executable and one in the test executable. And I'm not aware of any way to create an import library on Linux and to link with it.

I understand that I can divide my tested executable into a shared library with all the functionality in it and a small executable with only the main function in it. The test program would link with the shared library. But that's something I would really prefer not doing, since I have more than 20 of these executables that I need to test and dividing each of them into a shared library and an executable would take too long from number of reasons.

Another possibility would be to add the tested source code into the test project, but then the tested source code would be compiled twice, which I can't afford because of long build times.

So I'm trying to figure out if it is possible to do on Linux something similar to what I've done on Windows.

Thank you in advance.

I'm trying to figure out if it is possible to do on Linux something similar to what I've done on Windows.

No.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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