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

installation error: Undefined symbols for architecture arm64 #67

Closed
msarrias opened this issue Jan 14, 2022 · 5 comments
Closed

installation error: Undefined symbols for architecture arm64 #67

msarrias opened this issue Jan 14, 2022 · 5 comments

Comments

@msarrias
Copy link

Hi, when I try to compile CAFE 5 I get the following error:

g++ -std=c++11 -O3  -o bin/cafe5 -I. obj/base_model.o obj/cafexp.o obj/clade.o obj/core.o obj/easylogging++.o obj/error_model.o obj/execute.o obj/gamma.o obj/gamma_core.o obj/gene_family.o obj/gene_family_reconstructor.o obj/io.o obj/lambda.o obj/likelihood_ratio.o obj/matrix_cache.o obj/optimizer.o obj/optimizer_scorer.o obj/poisson.o obj/probability.o obj/root_equilibrium_distribution.o obj/simulator.o obj/user_data.o obj/main.o -lm
Undefined symbols for architecture arm64:
  "_omp_set_num_threads", referenced from:
      cafe5(int, char* const*) in cafexp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [bin/cafe5] Error 1

about my computer: MacOS Big Sur (version 11.2.3), apple M1 processor.

Any help is greatly appreciated!

@benfulton
Copy link
Member

You might try installing the OpenMP library

brew install libomp

Then run the configure and make steps again.

@msarrias
Copy link
Author

Thank you for your reply.

I already have the libomp library installed.

@benfulton
Copy link
Member

For some reason it didn't get picked up by the configure. Try editing the makefile manually and add

-fopenmp

to the line that starts

g++ -std=c++11 -O3 -o bin/cafe5...

@gnick18
Copy link

gnick18 commented Jun 13, 2022

Just wanted to add how I fixed this problem in case others come across it in the future! In short, it has to do with directives and functions not playing nicely with the newer MacOS. But a lot of the nuance goes way over my head. This StackOverflow forum is exactly how I ended up solving it!
StackOverflow link

In short I had to add not only
-fopenmp
but the following
-Xpreprocessor -fopenmp -lomp
on every line that was calling $(LINKER). I then tested cafe5 on the example files and it appears to be working! Will update this comment if I run into more issues later on.

To see the full Makefile example with the edits here is what mine looked:

#edited Makefile
# compilers and flags
CC=g++
CXX=g++
LD=g++


CFLAGS = -std=c++11 -I. -O3 -include config.h
LINKER = $(LD) -std=c++11 -O3  -o
LFLAGS = -I.

AUX =   CHANGELOG.md configure INSTALL LICENSE Makefile.in README.md config.h.in docs/tutorial examples Test_data

# directories
SRCDIR = src
OBJDIR = obj
BINDIR = bin

# our program
TARGET = cafe5

# Default build
all: prep release

release: $(BINDIR)/$(TARGET)


SOURCES := $(wildcard $(SRCDIR)/*.cpp)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
rm = rm -f

$(BINDIR)/$(TARGET): $(OBJECTS) $(OBJDIR)/main.o
	$(LINKER) $@ $(LFLAGS) $(OBJECTS) $(OBJDIR)/main.o -lm -Xpreprocessor -fopenmp -lomp

$(OBJECTS): $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

$(OBJDIR)/main.o: main.cpp
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJDIR)/test.o: test.cpp
	$(CC) $(CFLAGS) -c $< -o $@

.PHONY: clean
clean:
	$(rm) $(OBJECTS) $(OBJDIR)/main.o

.PHONY: remove
remove: clean
	@$(rm) $(BINDIR)/$(TARGET)

#
# Debug build settings
#
DBGDIR = debug
DBG_OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(DBGDIR)/%.o)
DBG_CFLAGS = -std=c++11 -Wall -Werror  -g -I. -include config.h $(INCLUDES) -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
DBG_LINKER = $(LD) -std=c++11  -o

$(DBG_OBJECTS): $(DBGDIR)/%.o: $(SRCDIR)/%.cpp
	$(CC) $(DBG_CFLAGS) -c $< -o $@

$(DBGDIR)/main.o: main.cpp
	$(CC) $(DBG_CFLAGS) -c $< -o $@

$(DBGDIR)/$(TARGET): $(DBG_OBJECTS) $(DBGDIR)/main.o
	$(DBG_LINKER) $@ $(LFLAGS) $(DBG_OBJECTS) $(DBGDIR)/main.o -lm -Xpreprocessor -fopenmp -lomp

.PHONY: debug
debug: $(DBGDIR)/$(TARGET)

TESTDIR = test
TEST_TARGET = runtests
TEST_OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(TESTDIR)/%.o)
$(TEST_OBJECTS): $(TESTDIR)/%.o: $(SRCDIR)/%.cpp
	$(CC) $(DBG_CFLAGS)  $(INCLUDES) -DSILENT -c $< -o $@

$(TESTDIR)/test.o: test.cpp
	$(CC) $(DBG_CFLAGS) -c $< -o $@

$(TESTDIR)/$(TEST_TARGET): $(TEST_OBJECTS) $(TESTDIR)/test.o
	$(LINKER) $@ $(LFLAGS) $(TEST_OBJECTS) $(TESTDIR)/test.o -lm -Xpreprocessor -fopenmp -lomp

.PHONY: test
test: $(TESTDIR)/$(TEST_TARGET)

prep:
	@mkdir -p $(OBJDIR) $(BINDIR) $(TESTDIR)

.PHONY: docs
docs:
	$(MAKE) -C docs

.PHONY: dist
dist: $(AUX)
	mkdir -p distro
	tar  --transform "s,^,CAFE5/," --transform "s,docs/,," --owner=0 --group=0 -czf distro/CAFE5-5.0.0.tar.gz src test.cpp main.cpp $(AUX)

@benfulton
Copy link
Member

Thanks, this is very helpful! I added a link to your answer to a new wiki page and will close this issue.

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

No branches or pull requests

3 participants