Vitalii
Vitalii

Reputation: 4803

Bypass static linking order problems in gcc

Static linking order is important for GCC, and it makes a lot of problems with static versions creation for a lot of widely used libraries, including libgd, libarchive, MySql Connector C, etc. Usually included configure script supposes that we use shared libraries, and even if we setup static build, it still ignores that fact and places static libraries in wrong order, so it consumes time to find the error and edit makefile manually.

From the other hand, competitor compilers can build static libraries in any order, for example, Microsoft Visual C++ doesn't have this problem, so it looks like must be a way to fix this issue.

Is there any way to force gcc to order static libraries automatically like Visual C++ does it?

Upvotes: 0

Views: 449

Answers (1)

Balamurugan Muthiah
Balamurugan Muthiah

Reputation: 559

Wrap the list of libraries with flags -Wl,--start-group and -Wl,--end-group during linking.

These flags ensures that all the unresolved symbols are looked up in all the mentioned libraries (independent of the order).

Upvotes: 2

Related Questions