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

macOS 10.15.6: Undefined symbols for architecture x86_64 #248

Open
scientificworld opened this issue Sep 30, 2020 · 19 comments
Open

macOS 10.15.6: Undefined symbols for architecture x86_64 #248

scientificworld opened this issue Sep 30, 2020 · 19 comments

Comments

@scientificworld
Copy link

When I run make, it shows this:

/bin/sh: fbc: command not found

So I tried to run make bootstrap.
But when linking, it tells me:

Undefined symbols for architecture x86_64:
  "_fb_ConsoleGetMouse", referenced from:
      _fb_GetMouse in hook_getmouse.o
  "_fb_ConsoleMultikey", referenced from:
      _fb_Multikey in hook_multikey.o
  "_fb_ConsoleSetMouse", referenced from:
      _fb_SetMouse in hook_setmouse.o
  "_fb_GfxGetJoystick", referenced from:
      _fb_GfxStickQB in gfx_stick.o
      _fb_GfxStrigQB in gfx_stick.o
  "_fb_SerialClose", referenced from:
      _fb_DevComClose in dev_com.o
  "_fb_SerialGetRemaining", referenced from:
      _fb_DevComEof in dev_com.o
      _fb_DevComTell in dev_com.o
  "_fb_SerialOpen", referenced from:
      _fb_DevComOpen in dev_com.o
  "_fb_SerialRead", referenced from:
      _fb_DevComRead in dev_com.o
      _fb_DevComReadWstr in dev_com.o
  "_fb_SerialWrite", referenced from:
      _fb_DevComWrite in dev_com.o
      _fb_DevComWriteWstr in dev_com.o
  "_fb_hGL_GetProcAddress", referenced from:
      _fb_GfxGetGLProcAddress in gfx_opengl.o
  "_fb_hIn", referenced from:
      _fb_In in hook_ports.o
      _fb_Wait in hook_ports.o
     (maybe you meant: _fb_hInit, _fb_hInitConsole )
  "_fb_hOut", referenced from:
      _fb_Out in hook_ports.o
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64

So how can I compile it on macOS?

@rversteegen
Copy link
Member

rversteegen commented Sep 30, 2020

First of all, it looks like you're trying to compile a program that makes use of graphics routines. But you can't compile such a program on Mac, as libfbgfx has not been ported to Mac*. Your options are either to stick to console programs, or use an external library like SDL or GTK or OpenGL.

Where did you get your bootstrap copy of the source code? The official bootstrap package doesn't include darwin (Mac OSX).
I did notice that you previously asked about the Mac port in #127 (comment).

*There is an unfinished and unmerged SDL2 backend for fbgfx though, which would allow a Mac port if it gets finished.

@rversteegen
Copy link
Member

Oh, my mistake, you got those errors because you ran make bootstrap, which tries to compile libfbgfx.

Edit makefile, find the line
bootstrap: rtlib gfxlib2 $(BOOTSTRAP_FBC)
near the bottom, and delete gfxlib2 from it.

@scientificworld
Copy link
Author

Oh, my mistake, you got those errors because you ran make bootstrap, which tries to compile libfbgfx.

Edit makefile, find the line
bootstrap: rtlib gfxlib2 $(BOOTSTRAP_FBC)
near the bottom, and delete gfxlib2 from it.

Thanks. I'll try it.

@scientificworld
Copy link
Author

Oh, my mistake, you got those errors because you ran make bootstrap, which tries to compile libfbgfx.

Edit makefile, find the line
bootstrap: rtlib gfxlib2 $(BOOTSTRAP_FBC)
near the bottom, and delete gfxlib2 from it.

I just found this line:
bootstrap: gfxlib2 bootstrap-minimal
And I try to remove gfxlib2, but it doesn't work.
There are still several errors when linking:

Undefined symbols for architecture x86_64:
  "_fb_ConsoleGetMouse", referenced from:
      _fb_GetMouse in hook_getmouse.o
  "_fb_ConsoleMultikey", referenced from:
      _fb_Multikey in hook_multikey.o
  "_fb_ConsoleSetMouse", referenced from:
      _fb_SetMouse in hook_setmouse.o
  "_fb_SerialClose", referenced from:
      _fb_DevComClose in dev_com.o
  "_fb_SerialGetRemaining", referenced from:
      _fb_DevComEof in dev_com.o
      _fb_DevComTell in dev_com.o
  "_fb_SerialOpen", referenced from:
      _fb_DevComOpen in dev_com.o
  "_fb_SerialRead", referenced from:
      _fb_DevComRead in dev_com.o
      _fb_DevComReadWstr in dev_com.o
  "_fb_SerialWrite", referenced from:
      _fb_DevComWrite in dev_com.o
      _fb_DevComWriteWstr in dev_com.o
  "_fb_hIn", referenced from:
      _fb_In in hook_ports.o
      _fb_Wait in hook_ports.o
     (maybe you meant: _fb_hInit, _fb_hInitConsole )
  "_fb_hOut", referenced from:
      _fb_Out in hook_ports.o
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64

So where is the main function?

@scientificworld
Copy link
Author

First of all, it looks like you're trying to compile a program that makes use of graphics routines. But you can't compile such a program on Mac, as libfbgfx has not been ported to Mac*. Your options are either to stick to console programs, or use an external library like SDL or GTK or OpenGL.

Where did you get your bootstrap copy of the source code? The official bootstrap package doesn't include darwin (Mac OSX).
I did notice that you previously asked about the Mac port in #127 (comment).

*There is an unfinished and unmerged SDL2 backend for fbgfx though, which would allow a Mac port if it gets finished.

Thank you so much. I successfully compiled it with gcc.

@scientificworld
Copy link
Author

First of all, it looks like you're trying to compile a program that makes use of graphics routines. But you can't compile such a program on Mac, as libfbgfx has not been ported to Mac*. Your options are either to stick to console programs, or use an external library like SDL or GTK or OpenGL.

Where did you get your bootstrap copy of the source code? The official bootstrap package doesn't include darwin (Mac OSX).
I did notice that you previously asked about the Mac port in #127 (comment).

*There is an unfinished and unmerged SDL2 backend for fbgfx though, which would allow a Mac port if it gets finished.

I'm sorry to bother you, but why I get an error when I was compiling an "Hello World" program?

$ fbc x.bas -gen llvm
x.bas() error 23: File not found, crt1.o
ld: library not found for -lgcc

@rversteegen
Copy link
Member

-gen llvm probably won't work on Mac (I've never tried it); use -gen gcc instead. In fact the -gen llvm emitter isn't finished and can't be used in general. Actually you shouldn't need -gen gcc since in my mac branch (which srvaldez also used) makes that the default.

Which build are you using?

@scientificworld
Copy link
Author

-gen llvm probably won't work on Mac (I've never tried it); use -gen gcc instead. In fact the -gen llvm emitter isn't finished and can't be used in general. Actually you shouldn't need -gen gcc since in my mac branch (which srvaldez also used) makes that the default.

Which build are you using?

I use -gen gcc and it tells me:
cc1: error: '-masm=intel' not supported in this configuration
fbc version: FreeBASIC Compiler - Version 1.08.0 (2020-10-01), built for darwin-x86_64 (64bit)
gcc version: gcc-10 (Homebrew GCC 10.2.0) 10.2.0
clang version: clang version 10.0.1
apple clang version: Apple clang version 11.0.3 (clang-1103.0.32.62)

@rversteegen
Copy link
Member

So which build of fbc are you using? Apparently you're using mine. Try using srvaldez's instead, see here. Looks like srvaldez patched it to not include crt1.o. I don't know why I didn't need to.

Also, make sure that fbc is invoking the homebrew gcc you installed, not the system gcc which is a symlink to clang. You can add -v to fbc's args to see what it's doing, and can set the GCC environmental variable to set whch gcc to use.

I hope it's not the case that Homebrew gcc has dropped -masm=intel.

@scientificworld
Copy link
Author

scientificworld commented Oct 2, 2020

So which build of fbc are you using? Apparently you're using mine. Try using srvaldez's instead, see here. Looks like srvaldez patched it to not include crt1.o. I don't know why I didn't need to.

Also, make sure that fbc is invoking the homebrew gcc you installed, not the system gcc which is a symlink to clang. You can add -v to fbc's args to see what it's doing, and can set the GCC environmental variable to set whch gcc to use.

I hope it's not the case that Homebrew gcc has dropped -masm=intel.

I use srvaldez's build to build commit 63d1c42 by myself.

@scientificworld
Copy link
Author

So which build of fbc are you using? Apparently you're using mine. Try using srvaldez's instead, see here. Looks like srvaldez patched it to not include crt1.o. I don't know why I didn't need to.

Also, make sure that fbc is invoking the homebrew gcc you installed, not the system gcc which is a symlink to clang. You can add -v to fbc's args to see what it's doing, and can set the GCC environmental variable to set whch gcc to use.

I hope it's not the case that Homebrew gcc has dropped -masm=intel.

I add -asm att and gcc also gives me an error:

x.bas() error 23: File not found, crt1.o
ld: warning: building for macOS 10.6 is deprecated
Undefined symbols for architecture x86_64:
  "start", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64

@scientificworld
Copy link
Author

So which build of fbc are you using? Apparently you're using mine. Try using srvaldez's instead, see here. Looks like srvaldez patched it to not include crt1.o. I don't know why I didn't need to.

Also, make sure that fbc is invoking the homebrew gcc you installed, not the system gcc which is a symlink to clang. You can add -v to fbc's args to see what it's doing, and can set the GCC environmental variable to set whch gcc to use.

I hope it's not the case that Homebrew gcc has dropped -masm=intel.

I generate a C file and it seems that the main function is missing.

typedef   signed char       int8;
typedef unsigned char      uint8;
typedef   signed short      int16;
typedef unsigned short     uint16;
typedef   signed int        int32;
typedef unsigned int       uint32;
typedef   signed long long  int64;
typedef unsigned long long uint64;
typedef struct { char *data; int64 len; int64 size; } FBSTRING;
typedef int8 boolean;
void fb_PrintString( int32, FBSTRING*, int32 );
FBSTRING* fb_StrAllocTempDescZEx( uint8*, int64 );
static void fb_ctor__x( void ) __attribute__(( constructor ));

__attribute__(( constructor )) static void fb_ctor__x( void )
{
	label$0:;
	FBSTRING* vr$0 = fb_StrAllocTempDescZEx( (uint8*)"hello", 5ll );
	fb_PrintString( 0, (FBSTRING*)vr$0, 0 );
	label$1:;
}

@scientificworld
Copy link
Author

So which build of fbc are you using? Apparently you're using mine. Try using srvaldez's instead, see here. Looks like srvaldez patched it to not include crt1.o. I don't know why I didn't need to.

Also, make sure that fbc is invoking the homebrew gcc you installed, not the system gcc which is a symlink to clang. You can add -v to fbc's args to see what it's doing, and can set the GCC environmental variable to set whch gcc to use.

I hope it's not the case that Homebrew gcc has dropped -masm=intel.

$ fbc -v x.bas -asm att
FreeBASIC Compiler - Version 1.08.0 (2020-10-01), built for darwin-x86_64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
target:       darwin-x86_64, x86-64, 64bit
backend:      gcc
compiling:    x.bas -o x.c (main module)
compiling C:  /usr/local/bin/../bin/gcc -m64 -march=x86-64 -S -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wno-format "x.c" -o "x.asm"
assembling:   as -arch x86_64 "x.asm" -o "x.o"
x.bas() error 23: File not found, crt1.o
linking:      ld -o "x" -L "/usr/local/bin/../lib/freebasic/darwin-x86_64" -L "." -L "/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0" "/usr/local/bin/../lib/freebasic/darwin-x86_64/fbrt0.o" "x.o" -lfb -lgcc -lSystem -lpthread -lncurses -macosx_version_min 10.6 
ld: warning: building for macOS 10.6 is deprecated
Undefined symbols for architecture x86_64:
  "start", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
linking failed: 'ld' terminated with exit code 1

rversteegen added a commit to rversteegen/fbc that referenced this issue Oct 3, 2020
…ecent OS/GCC

As suggested by srvaldez; fbc gh issue freebasic#248
@rversteegen
Copy link
Member

rversteegen commented Oct 3, 2020

main() is probably missing from your .c file because you ran fbc -r x.bas instead of fbc -r x.bas -m x. -m x tells that x.bas is the main module, which isn't implicit when using -r.

start is defined in crt1.o. Apparently starting in roughly mac OS 10.12, /usr/lib/crt1.o no longer exists, but will be created if you install "Command Line Tools for Mac OS X"? But that might have changed in macOS 10.15 and now that file is never created?

Looks like FreePascal may have hardcoded '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib as a library search path.

Try:
fbc x.bas -p '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib

If that doesn't work, try finding the correct patch by doing:

> clang -print-search-dirs

programs: =/Library/Developer/CommandLineTools/usr/bin
libraries: =/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0

> find /Library/Developer/CommandLineTools/ -name "crt1*"
/Library/Developer/CommandLineTools//SDKs/MacOSX.sdk/usr/lib/crt1.o
/Library/Developer/CommandLineTools//SDKs/MacOSX.sdk/usr/lib/crt1.10.5.o
/Library/Developer/CommandLineTools//SDKs/MacOSX.sdk/usr/lib/crt1.10.6.o

Also, if you run into further problems try compiling my mac branch instead of fbc/master, it has many fixes for Mac compile problems. It's currently a year behind the upstream master, but if that's a problem I could pull upstream. However I wouldn't actually be able to test it myself, since I don't have access to a Mac for about another week.

(Ignore that mention of the "don't link to crt1.o" commit I pushed; I reverted it after better understanding the problem)

@scientificworld
Copy link
Author

main() is probably missing from your .c file because you ran fbc -r x.bas instead of fbc -r x.bas -m x. -m x tells that x.bas is the main module, which isn't implicit when using -r.

start is defined in crt1.o. Apparently starting in roughly mac OS 10.12, /usr/lib/crt1.o no longer exists, but will be created if you install "Command Line Tools for Mac OS X"? But that might have changed in macOS 10.15 and now that file is never created?

Looks like FreePascal may have hardcoded '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib as a library search path.

Try:
fbc x.bas -p '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib

If that doesn't work, try finding the correct patch by doing:

> clang -print-search-dirs

programs: =/Library/Developer/CommandLineTools/usr/bin
libraries: =/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0

> find /Library/Developer/CommandLineTools/ -name "crt1*"
/Library/Developer/CommandLineTools//SDKs/MacOSX.sdk/usr/lib/crt1.o
/Library/Developer/CommandLineTools//SDKs/MacOSX.sdk/usr/lib/crt1.10.5.o
/Library/Developer/CommandLineTools//SDKs/MacOSX.sdk/usr/lib/crt1.10.6.o

Also, if you run into further problems try compiling my mac branch instead of fbc/master, it has many fixes for Mac compile problems. It's currently a year behind the upstream master, but if that's a problem I could pull upstream. However I wouldn't actually be able to test it myself, since I don't have access to a Mac for about another week.

(Ignore that mention of the "don't link to crt1.o" commit I pushed; I reverted it after better understanding the problem)

gcc:

install: /usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/
programs: =/usr/local/Cellar/gcc/10.2.0/libexec/gcc/x86_64-apple-darwin19/10.2.0/:/usr/local/Cellar/gcc/10.2.0/libexec/gcc/x86_64-apple-darwin19/10.2.0/:/usr/local/Cellar/gcc/10.2.0/libexec/gcc/x86_64-apple-darwin19/:/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/:/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/:/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/../../../../../../x86_64-apple-darwin19/bin/x86_64-apple-darwin19/10.2.0/:/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/../../../../../../x86_64-apple-darwin19/bin/
libraries: =/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/:/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/../../../../../../x86_64-apple-darwin19/lib/x86_64-apple-darwin19/10.2.0/:/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/../../../../../../x86_64-apple-darwin19/lib/:/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/../../../x86_64-apple-darwin19/10.2.0/:/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/../../../

clang:

programs: =/usr/local/opt/llvm/bin:/usr/local/Cellar/llvm/10.0.1_1/bin
libraries: =/usr/local/Cellar/llvm/10.0.1_1/lib/clang/10.0.1

apple clang:

programs: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
libraries: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3

I think I can link /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/crt1.o to these directories.
And I'll try to compile your mac branch.
Thanks for your help.

@scientificworld
Copy link
Author

scientificworld commented Oct 4, 2020

main() is probably missing from your .c file because you ran fbc -r x.bas instead of fbc -r x.bas -m x. -m x tells that x.bas is the main module, which isn't implicit when using -r.

start is defined in crt1.o. Apparently starting in roughly mac OS 10.12, /usr/lib/crt1.o no longer exists, but will be created if you install "Command Line Tools for Mac OS X"? But that might have changed in macOS 10.15 and now that file is never created?

Looks like FreePascal may have hardcoded '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib as a library search path.

Try:
fbc x.bas -p '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib

If that doesn't work, try finding the correct patch by doing:

> clang -print-search-dirs

programs: =/Library/Developer/CommandLineTools/usr/bin
libraries: =/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0

> find /Library/Developer/CommandLineTools/ -name "crt1*"
/Library/Developer/CommandLineTools//SDKs/MacOSX.sdk/usr/lib/crt1.o
/Library/Developer/CommandLineTools//SDKs/MacOSX.sdk/usr/lib/crt1.10.5.o
/Library/Developer/CommandLineTools//SDKs/MacOSX.sdk/usr/lib/crt1.10.6.o

Also, if you run into further problems try compiling my mac branch instead of fbc/master, it has many fixes for Mac compile problems. It's currently a year behind the upstream master, but if that's a problem I could pull upstream. However I wouldn't actually be able to test it myself, since I don't have access to a Mac for about another week.

(Ignore that mention of the "don't link to crt1.o" commit I pushed; I reverted it after better understanding the problem)

I compiled your mac branch and the error still exists... So I run ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/crt1.o /usr/local/Cellar/gcc/10.2.0/lib/gcc/10 and it compiled successfully, but with an warning: ld: warning: building for macOS 10.6 is deprecated.
Is there any way not to link it? Because when HomeBrew upgrade gcc, the symlink will be deleted.

@savetz
Copy link

savetz commented Feb 23, 2023

So... does fbc work on Mac or not?

@rversteegen
Copy link
Member

Well, there are no official builds FreeBASIC builds for Mac (and Mac/darwin isn't even included in the official bootstrap package). So I would say that FB's Mac port isn't really officially supported, but it can be made to work with some effort (e.g. installing gcc and/or using the right commandline args), except that fbgfx, the builtin library for graphics, has not been ported to Mac. It certainly needs work.

(BTW, Jeff merged my mac branch into this official fbc repo, except for updates to the crt headers.)

However, links to srvaldez's builds seem to be dead. My ancient build of pre-release FB-1.06 for Mac is still up. Don't know if there's some other available. Unfortunately I rarely have access to a Mac, so haven't put up a new one yet, or properly tested FB 1.09 on Mac, but other people have tried FB 1.09.
You can also compile it yourself by creating a custom bootstrap package.

@scientificworld
Copy link
Author

This issue is really old :D
Luckily I find the archive file of srvaldez's build for Catalina in my old Mac, you can download it below.
FB-Catalina.zip

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