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

Building on macOS #85

Closed
scottdotweb opened this issue Jan 10, 2023 · 2 comments
Closed

Building on macOS #85

scottdotweb opened this issue Jan 10, 2023 · 2 comments

Comments

@scottdotweb
Copy link

scottdotweb commented Jan 10, 2023

Hello, thanks so much for making this project. Here's what I had to do to build it on a Mac.

There are some things you could add to the README, and part of the build process needs tweaking, I think. As a proviso, I'm not a C++ developer and everything here I found out on the fly, so please forgive me if there's anything silly.

Building requires installing the Xcode command line tools, otherwise the build script will die with an error that xcrun is missing. You could link to the downloads page and the support table for which version of Xcode you need to work with your installed version of macOS. Alternatively they can be installed with xcode-select --install but I didn't find that out until I'd already done it manually, so not sure if that way takes the OS version into account.

On that point, I encountered a bit of an edge case - as I had to download an older version of the Xcode command line tools (in my case 13.4, to work with macOS 12.3), I ended up with a version of clang that doesn't understand -march=native in the build script. Apparently support for that arrived in clang 15. As I'm on a MacBook with an M1 processor, the workaround was to replace that flag with -mcpu=apple-m1 which became available in clang 13 (info via StackOverflow). I'm not sure what the case would be for other processors. Perhaps you could detect the installed clang version and CPU architecture and switch the flag in this situation?

Next up the user needs to install OpenSSL with brew install openssl. Then clang needs to be told where it is. After a lot of scrubbing through outdated answers on StackOverflow mentioning directories that are in different places now, I found this works:

cd /Library/Developer/CommandLineTools/usr/include
sudo ln -s /opt/homebrew/opt/openssl@3/include/openssl .

Maybe you can avoid that by adding something like -I/opt/homebrew/opt/openssl@3/include/openssl to the build steps? (This is pure speculation)

Finally, the linker invocation failed which required two fixes. Firstly it also needed to be told where OpenSSL is, which required adding -L/opt/homebrew/opt/openssl@3/lib.

Secondly there were some unrecognised flags. Currently it begins with:
-Wall -Wextra -Wl,-z,now -Wl,--as-needed -O3

That causes:

ld: warning: option -s is obsolete and being ignored
ld: unknown option: -z

Stripping out -s and Wl,-z,now causes: ld: unknown option: --as-needed. Strip that out too and it links successfully.

@bepaald
Copy link
Owner

bepaald commented Jan 10, 2023

Thank you so much for this write up. Before, it was slightly more involved to compile on Apple, due to llvm's c++ standard library not fully supporting c++17. This meant one had to install gcc (though it was just one more brew install command) as mentioned in #9. But, from your post I take it this is no longer necessary, that's good news.

As for the flags, almost all of them are optional, apart from a -std=c++17 (or higher, though I think c++17 might even be default in which case it can be omitted as well). The script is just a convenience thing, but generally I would just recommend people to compile as suggested in the relevant part of the readme:

"To compile the program, just running `g++ -std=c++2a */*.cc *.cc -lcrypto -lsqlite3` should generally 
do the trick. Add any compiler flags you feel useful, I personally use at least `-O3 -Wall -Wextra`."

Maybe you can avoid that by adding something like -I/opt/homebrew/opt/openssl@3/include/openssl to the build steps? (This is pure speculation)

Just adding something like this is probably not a good idea, looking at that path I assume the location of the library will be different if the user does not use homebrew to install openssl. I think users should probably know/research where their libraries are and update their $PATH's or add the needed compiler flags.

Likewise, I will not include instructions on how to install Xcode or openssl in the README of this project: those belong on their own respective project pages. Besides, I can't really keep those things up-to-date as I don't own a Mac. But I will link to your post in the README, that way macOs users should be able to follow your instructions to compile, and add more information if the instructions change with new versions.

Thanks again!

@bepaald bepaald closed this as completed Jan 10, 2023
@scottdotweb
Copy link
Author

Yep, that all makes sense. I have to admit that I hadn't read through your README in detail, I had gotten the suggestion to run the build script from the README for signal2html and then just ploughed straight into trying to make it work.

You're most welcome!

devnoname120 added a commit to devnoname120/signalbackup-tools that referenced this issue Mar 8, 2023
Fix bepaald#9
Fix bepaald#85
Fix bepaald#70
Fix bepaald#53
Fix bepaald#38
Fix bepaald#4
Fix bepaald#1

Note: we could easily add support for g++-8 by copy/pasting the following changes: https://github.com/InfiniTimeOrg/InfiniSim/pull/83/files
devnoname120 added a commit to devnoname120/signalbackup-tools that referenced this issue Mar 8, 2023
Fix bepaald#9
Fix bepaald#85
Fix bepaald#70
Fix bepaald#53
Fix bepaald#38
Fix bepaald#4
Fix bepaald#1

Note: we could easily add support for g++-8 by copy/pasting the following changes: https://github.com/InfiniTimeOrg/InfiniSim/pull/83/files
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 a pull request may close this issue.

2 participants