Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the default value of E57_RELEASE_LTO dependent on E57_BUILD_SHARED #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SunBlack
Copy link
Contributor

@SunBlack SunBlack commented Nov 29, 2024

By default BUILD_SHARED_LIBS is not defined, therefore the default of E57_BUILD_SHARED is also OFF. Therefore this lib will be build as static library by default. This leads by default to linker issues later:

/usr/bin/ld: /.../libE57Format.a(BlobNode.cpp.o): plugin needed to handle lto object

As the comment about E57_RELEASE_LTO says, this option should be OFF when building a static library. Therefore the default value is now adjusted accordingly. As changing E57_BUILD_SHARED later will not change the default value of E57_RELEASE_LTO I have added a warning so that there is a hint that the combination may cause issues.

GDAL has IPO disabled by default:
https://github.com/OSGeo/gdal/blob/305b23f5a90bf6d86c7fb895dfc745321def0aab/gdal.cmake#L27

Qt seems to also not set this value, but in case CMAKE_INTERPROCEDURAL_OPTIMIZATION is set they enforce it to OFF for MSVC 3rd party: qt/qtbase@0d708a9.

So basically I would argue that E57_RELEASE_LTO should be always OFF or removed and in case someone needs this, he can build it by passing CMAKE_INTERPROCEDURAL_OPTIMIZATION (in case canon has an issue with it, they can add it to their build script as it seems it was not necessary for vcpkg when checking the port scripts from before libE57Format 3.1.0 release)

if ( E57_RELEASE_LTO AND NOT E57_BUILD_SHARED )
message( WARNING "E57_RELEASE_LTO is set to ON, but ${PROJECT_NAME} will be build as static library. This may lead to linker issues!" )
elseif ( NOT E57_RELEASE_LTO AND E57_BUILD_SHARED )
message( WARNING "E57_RELEASE_LTO is set to OFF, but ${PROJECT_NAME} will be build as dynamic library. This may lead issues if compiling statically for distribution!" )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having it OFF for a dynamic lib isn't a problem. If they are compiling a dynamic lib, then they are are not "compiling statically for distribution".

Maybe I'm misunderstanding what you're trying to warn about here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only copied text from the comment, as it only says that there are problems, but nothing more. From #254 I also couldn't figure out why the option really has to be set as a default and couldn't just be added from outside if needed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're trying to package the lib for distribution, you can just turn it off by setting E57_RELEASE_LTO to OFF.

@asmaloney
Copy link
Owner

As the comment about E57_RELEASE_LTO says, this option should be OFF when building a static library.

It's actually talking specifically about release static builds for distribution.

which is a problem if compiling statically for distribution (e.g. in a package manager).
Generally you will only want to turn this off for distributing static release builds.

If you're using a static lib in your own code (i.e. including this library as a static lib) it's fine.

@SunBlack
Copy link
Contributor Author

If you're using a static lib in your own code (i.e. including this library as a static lib) it's fine.

Sadly not. See the linker issue in the initial post of me.

@asmaloney
Copy link
Owner

I use it as a static lib on macOS and Windows (MSYS2) without issues so this sounds like maybe a compiler difference.

What OS and compiler are you using?

@SunBlack
Copy link
Contributor Author

I use it as a static lib on macOS and Windows (MSYS2) without issues so this sounds like maybe a compiler difference.

What OS and compiler are you using?

On MSVC everything is fine with 3.2.0. On our CI we are using a docker image based on ubuntu:22.04 (my local VM is also Ubuntu 22.04 and there I have the same issue). Compiler is clang (19) and gcc (11).

@asmaloney
Copy link
Owner

I've never seen "plugin needed to handle lto object" - sounds like something isn't installed? Are you getting the same message from both clang and gcc on Ubuntu?

Any more info about it when you search for it?

@SunBlack
Copy link
Contributor Author

SunBlack commented Nov 29, 2024

I've never seen "plugin needed to handle lto object" - sounds like something isn't installed? Are you getting the same message from both clang and gcc on Ubuntu?

Tried again. On GCC I'm getting (build libE57 with GCC 11.3, but our project than with GCC 12.0):

lto1: fatal error: bytecode stream in file ‘/.../libE57Format/lib/libE57Format.a’ generated with LTO version 11.3 instead of the expected 12.0

So basically LTO seems to break the use case, to build a dependency with the default OS compiler and then compile it with a different compiler. Since we test our project on our CI with different GCC versions (standard OS compiler when we build a release so that we don't have to install another standard lib at the customer's site) and the latest compiler for more compiler warnings, you have to build multiple versions of libE57 (if you have LTO enabled) so that you can build with multiple compilers at the same time.

In principle, I have the feeling that you really don't want LTO as default, unless you build a release where you want to have a better optimization again - and in that case you can also activate it manually.

Any more info about it when you search for it?

Here for example

@asmaloney
Copy link
Owner

OK thanks. I'll consider it.

In the meantime, you should be able to set E57_RELEASE_LTO to OFF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants