part-cw / lambdanative

LambdaNative is a cross-platform development environment written in Scheme, supporting Android, iOS, BlackBerry 10, OS X, Linux, Windows, OpenBSD, NetBSD, FreeBSD and OpenWrt.
http://www.lambdanative.org
Other
1.4k stars 86 forks source link

multiple definition of `cmd_argv'; #410

Closed gassechen closed 3 years ago

gassechen commented 3 years ago

gcc -DLINUX -I/root/.cache/lambdanative/linux/include -DUSECONSOLE -o /root/.cache/lambdanative/linux/pngtool/pngtool -L/usr/local/linux/i686-linux/lib -L/root/.cache/lambdanative/linux/lib -lpayload -lrt -lutil -lpthread -ldl -lm /usr/bin/ld: /root/.cache/lambdanative/linux/lib/libpayload.a(system.o):(.bss+0x0): multiple definition of cmd_argv'; /root/.cache/lambdanative/linux/lib/libpayload.a(2978470258.o):(.bss+0x0): first defined here /usr/bin/ld: /root/.cache/lambdanative/linux/lib/libpayload.a(system.o):(.bss+0x8): multiple definition ofcmd_argc'; /root/.cache/lambdanative/linux/lib/libpayload.a(2978470258.o):(.bss+0x8): first defined here collect2: error: ld returned 1 exit status ERROR: failed with exit code 1 BUILD FAILED - configure with verbose option for more information make: *** [Makefile:2: all] Error 1

gassechen commented 3 years ago

more info: Reading specs from /usr/lib64/gcc/x86_64-slackware-linux/10.2.0/specs COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-slackware-linux/10.2.0/lto-wrapper Target: x86_64-slackware-linux Configured with: ../configure --prefix=/usr --libdir=/usr/lib64 --mandir=/usr/man --infodir=/usr/info --enable-shared --enable-bootstrap --enable-languages=ada,brig,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-threads=posix --enable-checking=release --enable-objc-gc --with-system-zlib --enable-libstdcxx-dual-abi --with-default-libstdcxx-abi=new --disable-libstdcxx-pch --disable-libunwind-exceptions --enable-__cxa_atexit --disable-libssp --enable-gnu-unique-object --enable-plugin --enable-lto --disable-install-libiberty --disable-werror --with-gnu-ld --with-isl --verbose --with-arch-directory=amd64 --disable-gtktest --enable-clocale=gnu --disable-multilib --target=x86_64-slackware-linux --build=x86_64-slackware-linux --host=x86_64-slackware-linux Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.2.0 (GCC)

mgorges commented 3 years ago

I believe this is a duplicate of #294, which reported this on Fedora 32? The strange thing is that I can't reproduce it on either of the three Linux systems I have access to, which are a Ubuntu 18.04.5, a current Gentoo (they don't version), or a Ubuntu 20.04.1. It seems to be related to -DUSECONSOLE, (or maybe related to GCC 10, but this is speculation from me here) and the other issue has some workarounds, but if you have suggestions on how to fix this universally we'd appreciate it.

gassechen commented 3 years ago

Change this lines in /liblambdanative/system.c

/* #ifdef USECONSOLE char **cmd_argv;

#endif char **cmd_argv;

#ifdef USECONSOLE int cmd_argc; #endif */

for this extern char **cmd_argv; extern int cmd_argc;

now compile for linux64 platform

gassechen commented 3 years ago

but a error try android compile [arm64-v8a] SharedLibrary : libpayloadshared.so /root/.lambdanative/tmp.dCSMEa/libpayload/arm64-v8a/libpayload.a(system.o): In function system_cmdargv': /root/.lambdanative/tmp_install/system.c:(.text+0x160): undefined reference tocmd_argc' /root/.lambdanative/tmp_install/system.c:(.text+0x164): undefined reference to cmd_argc' /root/.lambdanative/tmp_install/system.c:(.text+0x184): undefined reference tocmd_argv' /root/.lambdanative/tmp_install/system.c:(.text+0x188): undefined reference to cmd_argv' /root/.lambdanative/tmp.dCSMEa/libpayload/arm64-v8a/libpayload.a(system.o): In functionsystem_cmdargc': /root/.lambdanative/tmp_install/system.c:(.text+0x1b4): undefined reference to cmd_argc' /root/.lambdanative/tmp_install/system.c:(.text+0x1b8): undefined reference tocmd_argc' clang++: error: linker command failed with exit code 1 (use -v to see invocation) make[1]: [/root/Android/Sdk/ndk/ndk-21/build/core/build-binary.mk:725: obj/local/arm64-v8a/libpayloadshared.so] Error 1 make[1]: Leaving directory '/root/.lambdanative/tmp_build' ERROR: failed with exit code 2 BUILD FAILED make: [Makefile:2: all] Error 1

mgorges commented 3 years ago

Well that is what the #294 proposes, but it only works on Linux not Android. The part I don't yet understand is why this is happening, e.g. is it something related to gcc10, or something else entirely.

mgorges commented 3 years ago

I am wondering if it has something to do with https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93643, or is just a change to '-fno-common' see https://gcc.gnu.org/gcc-10/porting_to.html, which requires more use of extern. The definitions for Linux console apps are in three place libraries/liblambdanative/system.c, loaders/common/main.c, and loaders/hook/hook.c.

mgorges commented 3 years ago

I think we need to make sure that all versions of Linux apps still work with making extern the default, so all three: a) console apps, b) console apps including the scheduler, and c) GUI apps. If this does work, these two changes might work:

diff --git a/libraries/liblambdanative/system.c b/libraries/liblambdanative/system.c
index 5896640..739f56c 100644
--- a/libraries/liblambdanative/system.c
+++ b/libraries/liblambdanative/system.c
@@ -68,15 +68,8 @@ extern char* iphone_directory;

 #endif // !USECONSOLE

-#ifdef USECONSOLE
-extern 
-#endif
-char **cmd_argv;
-
-#ifdef USECONSOLE
-extern 
-#endif
-int cmd_argc;
+extern char **cmd_argv;
+extern int cmd_argc;

 static char *sys_appdir=0;
 static char *sys_dir=0;
diff --git a/loaders/android/bootstrap.c.in b/loaders/android/bootstrap.c.in
index 9550739..ca89ac7 100644
--- a/loaders/android/bootstrap.c.in
+++ b/loaders/android/bootstrap.c.in
@@ -46,6 +46,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 #include <LNCONFIG.h>

+int cmd_argc=0;
+char **cmd_argv;
 @ANDROID_C_DEFINES@

 // event hook
mgorges commented 3 years ago

It will also require a patch for iOS in loaders/ios/main.m and there likely would be other platforms too, so maybe this is not the best solution?

gassechen commented 3 years ago

im chage only in this file /targets/linux/host_linux

SYS_CC="gcc $SYS_DEBUGFLAG -DLINUX $cflag_additions" SYS_CXX="g++ $SYS_DEBUGFLAG -DLINUX $cflag_additions"

and add -fcommon and now compile for gcc-10.x

SYS_CC="gcc $SYS_DEBUGFLAG -DLINUX -fcommon $cflag_additions" SYS_CXX="g++ $SYS_DEBUGFLAG -DLINUX -fcommon $cflag_additions"

gassechen commented 3 years ago

Android compile DemoHybridApp-1.0-android-api29.apk Calculator-1.0-android-api29.apk

Linux64 compile DemoHybridApp Calculator

mgorges commented 3 years ago

Thanks - I will do a bit of testing and then apply it got Linux and MacOS too this evening.