I encountered the following error message when I try to compile using g++ on my macbook terminal
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
i was wondering if this issue has more to do with my compiler on my macbook terminal?
here's my whole command string, as i typed, with the output messages
1 2 3 4 5 6 7 8 9
(base) MacBook-Air% g++ -o compare comparestring.cpp
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(base) MacBook-Air%
See if this helps. I don't know what they are going on about, something about linking to allegro, which I know is an allergy medication. This looks like a different compiler, though, so maybe this is not relevant.
$ cat foo.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
usingnamespace std;
bool comp(string s1, string s2) {
return (s1 == s2);
}
int main(void) {
vector<string> v = {"ONE", "Two", "Three"};
bool result;
result = binary_search(v.begin(), v.end(), "one", comp);
if (result == true)
cout << "String \"one\" exist in vector." << endl;
v[0] = "Ten";
return 0;
}
$ g++ -o foo_program foo.cpp
$ nm -C foo_program | egrep ' [T] '
0000000000002948 T _fini
0000000000002940 T __libc_csu_fini
00000000000028d0 T __libc_csu_init
0000000000001412 T main
0000000000001300 T _start
00000000000013e9 T comp(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, \
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
There's main and comp from your code, and some stuff from the runtime support libraries.
You can also try the -v as it suggests. g++ -v -o foo_program foo.cpp
It prints a lot of information about what the compiler is up to.
It might indicate where it's going wrong.