file was built for archive which is not the architecture being linked (i386)

After struggling with this same problem and following all the accepted answers of updating build settings, clearing the linker search path, etc.. I finally discovered an answer that worked for me. Before building, make sure you select right type (iPhone Simulator) instead of iOS Device. Then rebuild. Otherwise, you’re trying to use a library built … Read more

Referencing memory operands in .intel_syntax GNU C inline assembly

Compile with gcc -masm=intel and don’t try to switch modes inside the asm template string. AFAIK there’s no equivalent before clang14 (Note: MacOS installs clang as gcc / g++ by default.) Also, of course you need to use valid GNU C inline asm, using operands to tell the compiler which C objects you want to … Read more

undefined reference to `strlwr’

strlwr() is not standard C function. Probably it’s provided by one implementation while the other compiler you use don’t. You can easily implement it yourself: #include <string.h> #include<ctype.h> char *strlwr(char *str) { unsigned char *p = (unsigned char *)str; while (*p) { *p = tolower((unsigned char)*p); p++; } return str; }

Multiple definition of … linker error

Don’t define variables in headers. Put declarations in header and definitions in one of the .c files. In config.h extern const char *names[]; In some .c file: const char *names[] = { “brian”, “stefan”, “steve” }; If you put a definition of a global variable in a header file, then this definition will go to … Read more

Q_OBJECT throwing ‘undefined reference to vtable’ error [duplicate]

It is because the unit generated by MOC isn’t included in the linking process. Or maybe it isn’t generated at all. The first thing I’d do is to put the class declaration in a separate header file, perhaps the build system isn’t scanning implementation files. Another possibility is that the class in question once didn’t … Read more

Error when compiling some simple c++ code

Normally this sort of failure happens when compiling your C++ code by invoking the C front-end. The gcc you execute understands and compiles the file as C++, but doesn’t link it with the C++ libraries. Example: $ gcc example.cpp Undefined symbols for architecture x86_64: “std::cout”, referenced from: _main in ccLTUBHJ.o “std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> … Read more

C error: undefined reference to function, but it IS defined

How are you doing the compiling and linking? You’ll need to specify both files, something like: gcc testpoint.c point.c …so that it knows to link the functions from both together. With the code as it’s written right now, however, you’ll then run into the opposite problem: multiple definitions of main. You’ll need/want to eliminate one … Read more