Compile Error On Ubuntu

Linux specific questions.
Post Reply
storm5510
Posts: 59
Joined: Nov 28, 2019 15:47

Compile Error On Ubuntu

Post by storm5510 »

I have a small program I wrote as a Windows application. I take the code to my Linux system and try to compile it and I get repeated errors, all the same, like below:
ld: /home/norman/FreeBASIC/bin/../lib/freebasic/linux-x86_64/libbig_int.a(basic_funcs.o):basic_funcs.c(.text+0x43): undefined reference to '_assert'
Any ideas, anyone?
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Compile Error On Ubuntu

Post by TJF »

Your file basic_funcs.bas contains a call to a function named _assert, but this function isn't declared.

If this function is in the library libbig_int.a, you've to DECLARE it in the FB code.
TeeEmCee
Posts: 375
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Compile Error On Ubuntu

Post by TeeEmCee »

No, that's not correct. This is a link error, not a compile error, so isn't caused by a missing declare, and anyway libbig_int is a library written in C, not a FB module.

I'm surprised you have a lib/freebasic/linux-x86_64/libbig_int.a file. Was that included with the copy of FB you downloaded, or did you install it?
My libc.so doesn't have an _assert function (only assert and __assert) and I don't think the extra underscore was added by the compiler, so I think maybe that libbig_int.a was compiled on a different system and isn't compatible with the system libraries on your system?
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Compile Error On Ubuntu

Post by TJF »

TeeEmCee wrote:No, that's not correct.
What's incorrect?

You talked about a compile error. I know, a message starting with ld: is comming from the linker.

And I think that we agree, that the linker couldn't bind the function named _assert.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Compile Error On Ubuntu

Post by D.J.Peters »

Link the right C runtime and the open reference are solved :-)

Or you used a wrong define (or the right define are missed -D NDEBUG) while you build the static C library !

Joshy
TeeEmCee
Posts: 375
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Compile Error On Ubuntu

Post by TeeEmCee »

TJF wrote:
TeeEmCee wrote:No, that's not correct.
What's incorrect?
You wrote "If this function is in the library libbig_int.a, you've to DECLARE it in the FB code" and that was what was incorrect. (I assumed you meant "you've got to DECLARE it")

Oh, when I said "compile error" I meant specifically an error produced while converting from FB to object file, but now I realise that might be confusing.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Compile Error On Ubuntu

Post by TJF »

TeeEmCee wrote:
TJF wrote:
TeeEmCee wrote:No, that's not correct.
What's incorrect?
... I assumed you meant ...
Based on an assumption you tell everybody that my entire statement is not correct? That's not quite respectable.
TeeEmCee
Posts: 375
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Compile Error On Ubuntu

Post by TeeEmCee »

Well, sorry, but I took what you wrote literally. Taken literally, it was wrong, and I think I'm right to point that out. I don't understand why you've taken offence, but it wasn't my intention to cause any.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Compile Error On Ubuntu

Post by TJF »

TeeEmCee wrote:Well, sorry, but I took what you wrote literally. Taken literally, it was wrong, ...
  • One of us translated and provided more then 20 high-quality header sets for C libraries, even complex ones like GDA, LDE or GTK.
  • One of us developed several tools to auto-create FB headers from C source and vice versa.
  • One of us knows what he is talking about when it comes to linking foreign libraries to FB code.
When the linker should bind a function from a library, it needs the parameter list and the type of the return value - it needs a DECLARE line in the FB code (bas/bi). My statement isn't incorrect, neither literally nor in any other case.

You shouldn't confuse beginners!
TeeEmCee
Posts: 375
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Compile Error On Ubuntu

Post by TeeEmCee »

I hardly read the forums and I wasn't very aware of your good work.
But I never assumed you didn't know what you were talking about. You could have claimed your expertise without attacking me. Do I really need to refute your bad-faith claim that I don't understand linking? I deal with arcane details of mixing C/C++/FB code all the time. I do it far more than is reasonable. I worked on the FB Android and Mac ports including system headers and linking and wrote two parsers for FB function declarations as part of transpilers to/from FreeBasic. I've checked the source code for quite a few linkers, assemblers, and object file parsers in order to understand behaviour, especially related to FB (e.g ports).
TJF wrote:My statement isn't incorrect, neither literally nor in any other case.
The problem here is that I kept talking about the error in the original post, and complained that your statement had nothing to do with that error. (Wasn't trying to blame you for misunderstanding after skimming, that's understandable.) You took offence and defended the things you wrote as true if taken in isolation without reference to any error message. I kept trying to address the original question, rather than change topic to declaring functions.

I got a bit upset that you attacked me after I tried to de-escalate this argument, and now I have to try yet again?? I said "sorry" genuinely, not ironically! Guess I need to stay out of your way.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Compile Error On Ubuntu

Post by fxm »

IMHO:

- A non declared neither defined procedure name induces a compiler error:

Code: Select all

'Declare Sub subroutine()

subroutine()
Compiler output:
FreeBASIC Compiler - Version 1.08.0 (2019-12-08), built for win32 (32bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
standalone
target: win32, 686, 32bit
compiling: C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.bas -o C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.c (main module)
C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.bas(3) error 42: Variable not declared, subroutine in 'subroutine()'
- An non defined but declared procedure name induces a linker error:

Code: Select all

Declare Sub subroutine()

subroutine()
Compiler output:
FreeBASIC Compiler - Version 1.08.0 (2019-12-08), built for win32 (32bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
standalone
target: win32, 686, 32bit
compiling: C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.bas -o C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.c (main module)
compiling C: C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\bin\win32\gcc.exe -m32 -march=i686 -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 -masm=intel "C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.c" -o "C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.asm"
assembling: C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\bin\win32\as.exe --32 --strip-local-absolute "C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.asm" -o "C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.o"
compiling rc: C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\bin\win32\GoRC.exe /ni /nw /o /fo "c:\users\fxmam\documents\mes outils personnels\freebasic-1.07.0-win32\bin\win32\res\fblogo.obj" "c:\users\fxmam\documents\mes outils personnels\freebasic-1.07.0-win32\bin\win32\res\fblogo.rc"
linking: C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\bin\win32\ld.exe -m i386pe -o "C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.exe" -subsystem console "C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\lib\win32\fbextra.x" --stack 1048576,1048576 -s -L "C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\lib\win32" -L "." "C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\lib\win32\crt2.o" "C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\lib\win32\crtbegin.o" "C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\lib\win32\fbrt0.o" "C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.o" "c:\users\fxmam\documents\mes outils personnels\freebasic-1.07.0-win32\bin\win32\res\fblogo.obj" "-(" -lfb -lgcc -lmsvcrt -lkernel32 -luser32 -lmingw32 -lmingwex -lmoldname -lgcc_eh "-)" "C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\lib\win32\crtend.o"
linking failed: 'C:\Users\fxmam\Documents\Mes Outils Personnels\fbc1.08.0.St_W\bin\win32\ld.exe' terminated with exit code 1
C:\Users\fxmam\Documents\Mes Outils Personnels\FBIde0.4.6r4_fbc1.08.0\FBIDETEMP.o:fake:(.text+0xcf): undefined reference to `SUBROUTINE@0'
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Compile Error On Ubuntu

Post by TJF »

@fxm:

We're talking about compiling against a library. Example

Code: Select all

TYPE AS LONG size_t

' correct:
'DECLARE FUNCTION memcpy CDECL LIB "c" ALIAS "memcpy"(BYVAL AS ANY PTR, BYVAL AS ANY PTR, BYVAL AS size_t) AS ANY PTR

' incorrect (name isn't present in the binary)
DECLARE FUNCTION memcpy CDECL LIB "c" ALIAS "_assert"(BYVAL AS ANY PTR, BYVAL AS ANY PTR, BYVAL AS size_t) AS ANY PTR
memcpy(0, 0, 0)
fbc -exx -w all "basic_funcs.bas"
basic_funcs.o: In Funktion `main':
basic_funcs.c:(.text+0x6d): undefined reference to '_assert'
Perhaps I should have written
TJF doesn't wrote:If this function is in the library libbig_int.a, you've to DECLARE it properly in the FB code.
, so that more people understand what's going on.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Compile Error On Ubuntu

Post by fxm »

Yes, it's clearer.
The alternate name (after Alias) is the one visible to the linker when linking with the library. If this name is incorrect, this will cause a linker error.
Post Reply