Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 views
in Technique[技术] by (71.8m points)

c++ - Should boost library be dependent on structure member alignments?

I found, the hard way, that at least boost::program_options is dependent of the compiler configured structure member alignment.

If you build boost using default settings and link it with a project using 4 bytes alignment (/Zp4) it will fail at runtime (made a minimal test with program_options). Boost will generate an assert indicating a possible bad calling convention but the real reason is the structure member alignment.

Is there any way to prevent this? If the alignment makes the code incompatible shouldn't this be included in library naming?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to ensure that your program and the libraries you link with have the same ABI.

The number of compiler switches that can alter the ABI of C++ classes and functions could be too large so it is clearly a problem to name more than 3000 combinations.

You could take a look here for a more detailed rationale.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...