conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
7.95k stars 951 forks source link

[question] How to compile C++ program for older version of MacOS? #16473

Closed stephane-archer closed 2 weeks ago

stephane-archer commented 2 weeks ago

What is your question?

here are my build steps:

conan install . --build=missing
cmake --preset conan-default
cmake --build --preset conan-release

this results in a binary that is compatible with only the current (last) version of MacOS

otool -l mybin
platform 1
    minos 14.5
      sdk 14.5

How to change this builds steps to compile for MacOS 10.14?

Have you read the CONTRIBUTING guide?

memsharded commented 2 weeks ago

Hi @stephane-archer

The way to control the inputs to Conan are mostly settings, options, conf and environment buildenv.

In this case we would be talking about settings. You can see them in your output, if you share the output of your conan install, you will see your current profile. You can see the general default settings.yml definition in https://docs.conan.io/2/reference/config_files/settings.html

Macos:
        version: [null, "10.6", "10.7", "10.8", "10.9", "10.10", "10.11", "10.12", "10.13", "10.14", "10.15",
                    "11.0", "11.1", "11.2", "11.3", "11.4", "11.5", "11.6", "11.7",
                    "12.0", "12.1", "12.2", "12.3", "12.4", "12.5", "12.6", "12.7",
                    "13.0", "13.1", "13.2", "13.3", "13.4", "13.5", "13.6",
                    "14.0", "14.1", "14.2", "14.3", "14.4", "14.5"]
        sdk_version: [null, "10.13", "10.14", "10.15", "11.0", "11.1", "11.3", "12.0", "12.1",
                        "12.3", "13.0", "13.1", "13.3", "14.0", "14.2", "14.4", "14.5"]
        subsystem:
            null:
            catalyst:
                ios_version: *ios_version

You can control those inputs defining things like -s os.version=13.4 -s os.sdk_version=13.1 in the command line, but in general it is recommended to define these values in profile files (and profile files can be managed as code, putting them in a git repo and sharing it with conan config install or conan config install-pkg if you want to put the profiles in a conan package)

stephane-archer commented 2 weeks ago

@memsharded First of all I would like to thank you for your precise and clear answer. I was able to build my program for MacOS 10.15 by adding os.version=10.15 to a conan2 profile located in ~/.conan2/profiles. here is what the new binary output:

 platform 1
    minos 10.15
      sdk 14.5

from my understanding, every MacOS 10.15 or higher should be able to run this program right? Is there any advantage to lowering the SDK, I'm not sure why it's part of the platform, to me an SDK is like a compiler, and the version you use is not really important. But my understanding might be wrong.

memsharded commented 2 weeks ago

from my understanding, every MacOS 10.15 or higher should be able to run this program right? Is there any advantage to lowering the SDK, I'm not sure why it's part of the platform, to me an SDK is like a compiler, and the version you use is not really important.

To be honest, I know little about the Apple ecosystem, I might need someone else to help.

Even the "compiler" version is factored into the Conan package_id and Conan treats as different binaries with different binary compatibility by default packages created with different compiler versions. Even if in theory binary compatibility should happen, there is ton of code out there with preprocessor macros using the compiler version to do different things that can affect even the API, but also the ABI in subtle ways (types sizes, alignment, etc).

With the SDK versions happen the same, there might be small differences in the binary that can make them incompatible. In general Apple SDKs keep good forward compatibility, no idea about backwards. This SDK version might also become more important not only for running, but for being linked together with other libraries.

stephane-archer commented 2 weeks ago

@memsharded Thank you! You are the best!