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

How to append linker options? #111

Open
GWRon opened this issue Dec 14, 2021 · 5 comments
Open

How to append linker options? #111

GWRon opened this issue Dec 14, 2021 · 5 comments

Comments

@GWRon
Copy link
Contributor

GWRon commented Dec 14, 2021

I was asked to get my game running on an ancient Linux (32bit, GLIBC <= 2.17).

I compiled NG's bcc and bmk with the help of vanilla bcc (and some adjustments). Some modules (GC stuff and some other in brl.mod) failed to compile with the ancient GCC (4.8 or 4.9 - tried on Cent OS 7 and Debian 8 MX 15).

So I compiled my own GCC (7.5) with the configure settings taken from my Mint setup.

The resulting binary (yeah!) failed to find CXXABI_1.3.9 - and strings found only up to CXXABI_1.3.8 in the system files (libstdc++.so.6).

I found out that one can append -static-libstdc++ to the g++ command doing the linking part after compilation. (yet I was not able to test the final binary - as it now blames the lack of hardware acceleration in my VM ... )

How can I define this to happen here - did not spot the right place in "custom.bmk" or "make.bmk" (bmk_utils.bmx does not seem to append custom/configurable stuff)

g++ -m32 -no-pie -fpie -pthread -o /home/.../TVTower /home/.../BlitzMax.NG/tmp/ld.tmp -L/usr/lib32 -L/usr/X11R6/lib -L/usr/lib
->
g++ -m32 -no-pie -fpie -pthread -static-libstdc++ -o /home/.../TVTower /home/.../BlitzMax.NG/tmp/ld.tmp -L/usr/lib32 -L/usr/X11R6/lib -L/usr/lib
@woollybah
Copy link
Member

You could try adding an ld_opts option...

setldopt static-stdc -static-libstdc++

But it doesn't let you specify the order it is added.

@woollybah
Copy link
Member

It's also possible to use makebootstrap to generate bcc/bmk sources that can be used as a base to compile on a particular system.
You tweak the bootstrap.cfg file with the target platform, and you'll need bcc and bmk in the src dir.
And the run something like :

./bmk makebootstrap

Creates a dist dir which you can zip up and drop onto a system.
Then run one of the build scripts in bcc/bmk to generate an executable. eg.

source bmk.console.release.linux.x86.build

@GWRon
Copy link
Contributor Author

GWRon commented Dec 15, 2021

setldopt (or addldopt) seems to be ignored somehow ... will investigate and report back (so you can do something else meanwhile).
bmk_make.bmx:

print "Linking options:"
print globals.Get("ld_opts").ToString()

LinkApp opt_outfile, links, makelib, globals.Get("ld_opts")

custom.bmk

setldopt static-stdc -static-libstdc++
addldopt static-stdc -static-libstdc++
$ ./bmk makeapp -r -v /home/ronny/Arbeit/Projekte/TVTower/Current/TVTower.bmx
[100%] Linking:TVTower
Linking options:
 -static-libstdc++ -static-libstdc++
g++ -m64 -no-pie -fpie -pthread -o /home/ronny/Arbeit/Projekte/TVTower/Current/TVTower /home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/ld.tmp -L/usr/X11R6/lib -L/usr/lib
Loading post.bmk

Regarding the makebootstrap - yeah surely an option too, but I think in this scenario the "ld_opts" are versatile enough (once working). Thanks for the suggestion though.

@GWRon
Copy link
Contributor Author

GWRon commented Dec 15, 2021

Saw this in bmk_util.bmx (linkapp - for win32):

		If usingLD
			If opts.Find("stdc++") = -1 Then
				fb.Append(" -lstdc++")
			End If

Wouldn't it then be better to search for "-lstdc++" (to avoid skipping appending -lstdc++ when using "static-libstdc++" ? (did not check if the static-libstdc++ already inclused -lstdc++ ... or if there are other params containing "stdc++")

@GWRon
Copy link
Contributor Author

GWRon commented Dec 15, 2021

Regarding "ld_opts": they are ignored on linux ...

bmk_util.bmx - linkapp():

	If processor.Platform() = "macos" Or processor.Platform() = "osx" Then
...
		If opts Then
			sb.Append(" ").Append(opts)
		End If

	If processor.Platform() = "win32"
...
		' add any user-defined linker options
		fb.Append(" ").Append(opts)

		' add any user-defined linker options, again - just to cover whether we missed dependencies before.
		fb.Append(" ").Append(opts)

	If processor.Platform() = "linux" Or processor.Platform() = "raspberrypi" Or processor.Platform() = "haiku"
...
	If processor.Platform() = "android" Then
...
	If processor.Platform() = "emscripten"
...
		sb.Append(" ").Append(opts)

	If processor.Platform() = "nx" Then
        EndIf
...
	Local t$=getenv_( "BMK_LD_OPTS" )
	If t 
		sb.Append(" ").Append(t)
	EndIf

I truncated the code a bit to make it easier to spot where "opts" is not used. Also it shows that on Windows, you append the options twice. Dunno if the first could be removed? Or if this can raise issues when used twice (so you'd better kinda "split" what can be added before and what needs to come afterwards)

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

2 participants