mercredi 9 mars 2022

Issue running clang++ compiler on m1 pro?

I get the following error when trying to compile my simple program with make all:

❯ make all
clang++ --std=c++11 -Wall main.cpp
Undefined symbols for architecture arm64:
  "file_reader::read_file()", referenced from:
      _main in main-99040e.o
  "file_reader::file_reader(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      _main in main-99040e.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main.o] Error 1

I can compile the program manually if I do clang++ --std=clang++11 main.cpp file_reader.cpp (and the executable works correctly), so I don't think it's an architecture error like it suggests. I think it might be a problem with my makefile, which I will include below, so if anyone has any insight that would be really helpful. I looked up several conventions for makefiles and none of them helped. The structure is pretty basic with main.cpp creating an object of type file_reader and then referencing one of its methods, so I use #include "file_reader.h" in my main.cpp.

makefile:

# compiler
CXX = clang++

# compiler flags:
#   --std=clang++11 : verion
CXXFLAGS = --std=c++11 -Wall

all: main.out

main.out: main.o file_reader.o
    $(CXX) main.o file_reader.o -o main

main.o: main.cpp file_reader.h
    $(CXX) $(CXXFLAGS) main.cpp

file_reader.o: file_reader.cpp file_reader.h
    $(CXX) $(CXXFLAGS) file_reader.cpp

clean:
    rm -rf *.o restaurant

Aucun commentaire:

Enregistrer un commentaire