imp____acrt_iob_func, undefined

General FreeBASIC programming questions.
Post Reply
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

imp____acrt_iob_func, undefined

Post by srvaldez »

I have been keeping msys2 updated to the latest and today I decided to build FB from source again, everything went well until I tried to compile something, I would get the error \lib\win32/libfb.a(init.o):init.c:(.text+0x97): undefined reference to `_imp____acrt_iob_func'
fortunately I had a backup of an earlier version of msys2 and all is well again, I won't be so self-confident next time.
just the same, does anyone know the solution to this problem? google didn't help.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: imp____acrt_iob_func, undefined

Post by srvaldez »

found the solution, one needs to replace the gcc libraries with the newer.
integer
Posts: 408
Joined: Feb 01, 2007 16:54
Location: usa

Re: imp____acrt_iob_func, undefined

Post by integer »

srvaldez wrote:found the solution, one needs to replace the gcc libraries with the newer.
Where are the latest gcc libs?
and just wondering: If you kept msys current & using the latest FBC to complile the fbc, how did you miss the gcc libs?
That might provide some answers for problems I've had with compiling the compiler.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: imp____acrt_iob_func, undefined

Post by srvaldez »

hello integer
yes I keep msys2 up to date, in the past I didn't bother updating all the libraries, jus the ones belonging to FB, but things changed a bit in the gcc libraries and was getting the above error, besides it's better to have updated libs.
I don't know what your gcc toolchain looks like, do you have msys2 installed as well or some other mingw distribution?
I would recommend that you install the FB package that's designed to be integrated in the toolchain, makes it easier to re-build FB.
I have both 32 and 64-bit versions in the gcc toolchain as well as standalone versions which I use most of the time.
let me know what your setup is and what you have tried.
integer
Posts: 408
Joined: Feb 01, 2007 16:54
Location: usa

Re: imp____acrt_iob_func, undefined

Post by integer »

Thanks srvaldez.

I tried several dozen times in the past years to compile the compiler on a xp and Win7. With each failure I would erase the files and reinstall all that I believed the developer pages identified. There were a bunch of errors that made no sense. My "corrections" to those messages weren't -- and the attempt to compile the compiler puked.

Now that I have a WenTin Box (as of last year) one of my goals this year is to compile both the 32bit FBC and the 64bit FBC.
The cpu is an AMD 8-core.
I will install msys & the toolchain on the Win10.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: imp____acrt_iob_func, undefined

Post by srvaldez »

hello integer
I recommend msys2 http://www.msys2.org or https://sourceforge.net/projects/msys2/ , it's actively being maintained, so much so that sometimes there are updating problems, but if you skip checking for updates on Tuesdays you probably won't run into problems.
Tuesday as you may know is systems software update day, so skip Tuesday and you should be ok.
Iczer
Posts: 99
Joined: Jul 04, 2017 18:09

Re: imp____acrt_iob_func, undefined

Post by Iczer »

I'm run into same problem with undefined __imp___acrt_iob_func

Code: Select all

***\FreeBASIC-1.06.0-win64\lib\win64/libcurl.a(mprintf.o):(.text+0x1b58): undefined reference to `__imp___acrt_iob_func'
***\FreeBASIC-1.06.0-win64\lib\win64/libcurl.a(mprintf.o):(.text+0x1bf3): undefined reference to `__imp___acrt_iob_func'
***\FreeBASIC-1.06.0-win64\lib\win64/libcurl.a(setopt.o):(.text+0x190b): undefined reference to `__imp___acrt_iob_func'
***\FreeBASIC-1.06.0-win64\lib\win64/libcurl.a(cookie.o):(.text+0x1a0): undefined reference to `__imp___acrt_iob_func'
***\FreeBASIC-1.06.0-win64\lib\win64/libcurl.a(cookie.o):(.text+0x26e4): undefined reference to `__imp___acrt_iob_func'
***\FreeBASIC-1.06.0-win64\lib\win64/libcurl.a(url.o):(.text+0x4e9): more undefined references to `__imp___acrt_iob_func' follow
if i get fresh mingw64 (v8.1+) and copy "libstdc++.a" (am i right?) to FreeBasic "\lib\win64\" folder will it solve issue?

googled some related discussion:
https://stackoverflow.com/questions/304 ... -func-sdl2
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: imp____acrt_iob_func, undefined

Post by caseih »

I think you're seeing some incompatibilities between the version of Mingw or Visual Studio that compiled libcurl, and your version of the MingW compiler/linker suite. I suspect it's something to do with changes to MS C runtime. But that's as far as I've got. At a low level I think MS changed some of underlying implementation of certain C runtime routines over the last few years. This link talks about the changes: https://msdn.microsoft.com/en-us/librar ... spx#BK_CRT

Here's a discussion of this type of error: https://stackoverflow.com/questions/304 ... -func-sdl2

No idea how to resolve this from FBC though.
Iczer
Posts: 99
Joined: Jul 04, 2017 18:09

Re: imp____acrt_iob_func, undefined

Post by Iczer »

__iob_func() function it seems provided by msvcr120.dll, but including #inclib "msvcr120" not resolve issue. I tried to declare __iob_func() like this:

Code: Select all

Declare function  __acrt_iob_func(ByVal index As UInteger) as FILE ptr
#Define stdin __acrt_iob_func(STDIN_FILENO)
#Define stdout __acrt_iob_func(STDOUT_FILENO)
#Define stderr __acrt_iob_func(STDERR_FILENO)
because ():

Code: Select all

Here's a snippet from the Visual Studio 2008 headers:

_CRTIMP FILE * __cdecl __iob_func(void);
#define stdin (&__iob_func()[0])
#define stdout (&__iob_func()[1])
#define stderr (&__iob_func()[2])

Visual Studio 2015 defines the same things:

_ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned);
#define stdin (__acrt_iob_func(0))
#define stdout (__acrt_iob_func(1))
#define stderr (__acrt_iob_func(2))
maybe this should eliminate errors (but not work if actually called), but i do not know how translate it to freebasic:

Code: Select all

FILE _iob[] = {*stdin, *stdout, *stderr};

extern "C" FILE * __cdecl __iob_func(void)
{
    return _iob;
}
or this:

Code: Select all

'typedef FILE *__cdecl (*_f__acrt_iob_func)(unsigned index);
'_f__acrt_iob_func __MINGW_IMP_SYMBOL(__acrt_iob_func) = __acrt_iob_func;
'"#;
Iczer
Posts: 99
Joined: Jul 04, 2017 18:09

Re: imp____acrt_iob_func, undefined

Post by Iczer »

I successfully get around issue by creating:

Code: Select all

#Include Once "crt.bi"

Extern "C"

Declare Function __acrt_iob_func (ByVal index As ULong) As FILE Ptr

Function __acrt_iob_func(ByVal index As ULong) As FILE Ptr
	Return @(__iob_func()[index])
End Function

Declare Function __imp___acrt_iob_func (ByVal index As ULong) As FILE Ptr

Function __imp___acrt_iob_func(ByVal index As ULong) As FILE Ptr
	Return @(__iob_func()[index])
End Function

End Extern

#Undef stdin
#Undef stdout
#Undef stderr

#Define stdin (__acrt_iob_func(STDIN_FILENO_))
#Define stdout (__acrt_iob_func(STDOUT_FILENO))
#define stderr (__acrt_iob_func(STDERR_FILENO))
Code compilibg without warnings, programm start ok, but crash on first call of curl...
Maybe stdin/stdout/stderr realisation wrong in my snippet?
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: imp____acrt_iob_func, undefined

Post by srvaldez »

while testing libraries produced by MXE (cross environment) https://mxe.cc/ I ran into this issue again
was testing libcairo and Iczer's solution did solve the undefined symbol problem but the cairo clock would crash
so tried including different msvcrt libs without Iczer's solution thinking that perhaps the cause of the crash was there
I found that #inclib "msvcrt-os" would make the error go away but it would still crash
so I tested libgmp and libmpfr and either Iczer's solution or #inclib "msvcrt-os" would work
[edit]
on another test, Iczer's solution caused a crash whereas #inclib "msvcrt-os" would work ok
Last edited by srvaldez on Sep 03, 2020 19:41, edited 1 time in total.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: imp____acrt_iob_func, undefined

Post by srvaldez »

the 32-bit tests of libcairo works ok, I suspect that the cairo bi files are not 64-bit clean
Post Reply