Reputation: 3032
I'm trying to build a universal/fat executable binary and I'm linking against ncurses. I'm using ncurses from homebrew because the built in one doesn't support wide characters.
The problem seems to be -L/path/to/arm/libs -L/path/to/intel/libs
never searches the intel libs because it finds the proper named lib in /path/to/arm/libs
. Then it complains about the architecture being wrong. It is wrong, but I want clang to keep looking in the other paths for the one that has the right name and architecture.
Is this possible? Do I have to use lipo or something else to build a fat lib from the separate arm and intel libs?
Here is my minimal app. It draws a border around your terminal window.
#define _XOPEN_SOURCE_EXTENDED
#include <ncursesw/curses.h>
#include <clocale>
int main(int argc, char* argv[]) {
setlocale(LC_ALL, "");
initscr();
raw();
noecho();
keypad(stdscr, true);
refresh();
wborder_set(stdscr, WACS_D_VLINE, WACS_D_VLINE, WACS_D_HLINE, WACS_D_HLINE,
WACS_D_ULCORNER, WACS_D_URCORNER, WACS_D_LLCORNER, WACS_D_LRCORNER);
getch();
endwin();
return 0;
}
Here are my build steps. I'm actually using a makefile but these lines are able to build non-fat apps if I only specify one arch and the matching lib path when linking.
clang++ -std=c++17 -Wall -fno-objc-arc -finput-charset=UTF-8 -I/opt/homebrew/opt/ncurses/include -arch arm64 -arch x86_64 -c -o main.o main.cpp
clang++ -L/opt/homebrew/opt/ncurses/lib -L/usr/local/homebrew/opt/ncurses/lib -lncurses -arch arm64 -arch x86_64 -o test main.o
Upvotes: 1
Views: 293
Reputation: 3032
Here's what I did.
I added a new make target for build/lib/libncurses.a
I set its dependencies to the two libncurses.a files installed by homebrew. They're symlinks to libncursesw.a but this still works. I was a little worried by what file gave me for the two libs. /opt/homebrew/opt/ncurses/lib/libncurses.a: current ar archive random library
Neither file specified an architecture so I was worried. For the rule I used lipo to join the two files into a multi-arch lib.
In the end these were the relevant parts of my makefile.
# Add our new libdir to the linker's lib path.
LDFLAGS += -L$(BUILD_DIR)/lib
# We make our own fat libs cause homebrew doesn't want to.
$(BUILD_DIR)/lib/libncurses.a: $(BREW_PREFIX)/opt/ncurses/lib $(BREW86_PREFIX)/opt/ncurses/lib
lipo -create -output ./build/lib/libncurses.a $(BREW_PREFIX)/opt/ncurses/lib/libncurses.a $(BREW86_PREFIX)/opt/ncurses/lib/libncurses.a
I'm working on a good way to support other installations of ncurses like from macports or just extracting the tarball and building it yourself so suggestions are appreciated. I'm still hoping somebody comes up with a better answer though.
Upvotes: 1