I am getting the following persistent errors trying to debug a C program in Eclipse Juno on my mac:
Building target: TimeStamps
Invoking: MacOS X C Linker
gcc -v -o "TimeStamps" ./graphic/arrow.o ./graphic/axesdraw.o . . .
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -o
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [TimeStamps] Error 1
So, I am confused about how to fix this in Eclipse. The main routing is in timestamp_test.c
I have -g -v as compiler flags, and -v as a linker flag.
No .o files are made.
Based on the the error given, you need to add the main function to timestamp_test.c.
Or pass the file that have the main function implemented to the compiler.
Related
In my compilers class we are writting Flex/Lex code. When I compiled the .l file and tried to compile the resultant lex.yy.c file with gcc, I got the following error:
Undefined symbols for architecture arm64:
"_yywrap", referenced from:
_yylex in lex-fb85c9.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does is posible to compile it in a Apple Silicon (M1) Mac, at least in a Linux VM?
I created a test file and compiled:
% flex lex.l
% cc -o lex lex.yy.c -lc -ll
% grep 'yylex();' lex.yy.c
yylex();
The -ll on the cc command links against the libl library. Current M1 based macOS does not provide a libfl library you may see referenced.
I am writing a simple "Hello world" program using MacBook Air 2020 (M1) and the C code is as follows:
#include<stdio.h>
int main(void){
printf("Hello world!\n");
return 0;
}
clang version is
Apple clang version 14.0.0 (clang-1400.0.29.201)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
However after I compiled it and try to run ld hello.o -o hello it gives the following error:
Undefined symbols for architecture arm64:
"_puts", referenced from:
_main in hello.o
ld: symbol(s) not found for architecture arm64
Why is the symbol not defined?
Link using the compiler (clang hello.o -o hello) — it will add the standard C library and the startup code, etc to the ld command line.
Add -v to the options to see what the compiler actually executes.
On an Intel Mac running macOS Big Sur 11.7, part of the information produced was this humungous long line which invokes the loader (ld) in a ridiculously obscure location:
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 11.0.0 12.1 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o tm59 -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib -L/usr/local/lib /var/folders/sj/_v4_1hp947d_6qg_m75syr000000gn/T/tm59-7bf6b1.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/lib/darwin/libclang_rt.osx.a
I'm trying to compile the following libusb snippet on my Mac:
#include <stdio.h>
#include <stdlib.h>
#include <libusb.h>
int main(void) {
libusb_device **devices;
ssize_t device_count = 0;
device_count = libusb_get_device_list(NULL, &devices);
printf("%d devices found\n", (int)device_count);
return EXIT_SUCCESS;
}
I have libusb installed via Homebrew.
I'm getting the following error during compilation:
ld: symbol(s) not found for architecture x86_64
The full compiler output is as follows:
22:28:24 **** Incremental Build of configuration Debug for project libusb ****
make all
Building file: ../src/libusb.c
Invoking: Cross GCC Compiler
gcc -I/usr/local/Cellar/libusb/1.0.9/include/libusb-1.0/ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/libusb.d" -MT"src/libusb.d" -o "src/libusb.o" "../src/libusb.c"
Finished building: ../src/libusb.c
Building target: libusb
Invoking: Cross GCC Linker
gcc -o "libusb" ./src/libusb.o
Undefined symbols for architecture x86_64:
"_libusb_get_device_list", referenced from:
_main in libusb.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libusb] Error 1
22:28:24 Build Finished (took 119ms)
I understand the problem is to do with the linker not finding the libusb library, right? How do I tell the compiler where that is in Eclipse CDT?
As we worked out in all the comments the link command that worked is
gcc -L/usr/local/Cellar/libusb/1.0.9/lib -o "libusb_example" ./src/libusb_example.o -lusb1.0
My environment:
OS: OSX ML 10.8.5
VIM: 7.4
GCC: 4.2.1 (Apple LLVM version 5.0)
GDB: GNU gdb 6.3.50-20050815
I want to debugging in VIM with C programming language. After I seached Google, I found Clewn, but when I make it, it returned the following messages.
make all-recursive
Making all in .
gcc -DHAVE_CLEWN -g -O2 -Wall -o clewn clewn.o gdb_lvl2.o gdb_lvl3.o misc.o netbeans.o obstack.o pty.o -lreadline -lcurses
Undefined symbols for architecture x86_64:
"_ding", referenced from:
_clewn_beep in misc.o
"_rl_getc", referenced from:
_cli_getc in clewn.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [clewn] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
Excuse for my English, hope you know what I means. And thank you so much!!!
I haven't used clewn since around 2007–2008 and never on OS X, but you could try the following to at least get it to compile.
"_ding", referenced from:
_clewn_beep in misc.o
Simply comment out the body of the clewn_beep function. At least for now.
"_rl_getc", referenced from:
_cli_getc in clewn.o
Try replacing the call to rl_getc in clewn.c with a call to cli_getc and see if that works.
I also had to add the following line in clewn.c to get it to compile (OS X 10.8.5):
extern int rl_done;
Ok, what we have:
Program written on C which compiling and running without problems in Linux and MacOSX (leopard).
I embedded lua code today. Linux: compiled lua 5.1 from source. Everything works and compiles without any problems. Macos: compiled the same lua 5.1 package.
Linked with --llua.
Started compile and got an error:
CC=gcc-4.0 make
ld: warning: in /usr/local/lib/liblua.a, file is not of required architecture
Also tried reinstall, complete remove and installing from macports. The same.
So is there any fix for that?
The error "file is not of required architecture" hints to the fact that you're trying to mix architectures.
Check the architecture of the /usr/local/lib/liblua.a and make sure it matches the architecture or the object you're trying to build.
E.g.
We have a i386 object:
==== cat fun.c ====
#include <stdio.h>
void fun()
{
printf("%s", "foobar\n");
}
gcc -arch i386 -c fun.c -o fun.o
if we try to use it when compiling a x86_64 object (default architecture in Mac OS X):
===== cat test.c ==
extern void fun();
int main()
{
fun();
}
we get:
$ gcc test.c fun.o
ld: warning: ignoring file fun.o, file was built for i386 which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
"_fun", referenced from:
_main in ccXVCQhG.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status