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

Failed to build on Ubuntu-18.04 missing -lffi #1738

Open
mingodad opened this issue Oct 13, 2022 · 3 comments
Open

Failed to build on Ubuntu-18.04 missing -lffi #1738

mingodad opened this issue Oct 13, 2022 · 3 comments

Comments

@mingodad
Copy link

When trying to build on Ubuntu 18.04 64bits I was getting errors trying to link with libffi:

Building BeefBuild_bootd
[                              ]�������������������������������******************************
TIMING: Beef compiling: 61.7s
Comptime execution time: 0.23s
Linking BeefBuild_bootd..../libBeefRT_d.a(Internal.cpp.o): In function `bf::System::FFI::FFILIB::ClosureAlloc(long, void**)':
/home/mingo/dev/c/A_programming-languages/Beef/BeefRT/rt/Internal.cpp:953: undefined reference to `ffi_closure_alloc'
./libBeefRT_d.a(Internal.cpp.o): In function `bf::System::FFI::FFILIB::PrepCif(bf::System::FFI::FFILIB::FFICIF*, bf::System::FFI::FFIABI, int, bf::System::FFI::FFIType*, bf::System::FFI::FFIType**)':
/home/mingo/dev/c/A_programming-languages/Beef/BeefRT/rt/Internal.cpp:962: undefined reference to `ffi_prep_cif'
./libBeefRT_d.a(Internal.cpp.o): In function `bf::System::FFI::FFILIB::Call(bf::System::FFI::FFILIB::FFICIF*, void*, void*, void**)':
/home/mingo/dev/c/A_programming-languages/Beef/BeefRT/rt/Internal.cpp:971: undefined reference to `ffi_call'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
FAIL: Exit code returned: 1

After looking around I found this changes that allowed me to build:

------------------------------ IDE/src/IDEApp.bf ------------------------------
index ae5a0c64..e2e20b92 100644
@@ -10194,7 +10194,7 @@ namespace IDE
 										newString.AppendF("./{} -Wl,-rpath -Wl,@executable_path", rtName);
 									case .iOS:
 									case .Linux:
-										newString.AppendF("./{} -lpthread -ldl -Wl,-rpath -Wl,$ORIGIN", rtName);
+										newString.AppendF("./{} -lpthread -ldl -lffi -Wl,-rpath -Wl,$ORIGIN", rtName);
 									case .Wasm:
 										newString.Append("\"");
 										newString.Append(mInstallDir);

--------------------------- IDEHelper/CMakeLists.txt ---------------------------
index dc41ea2d..8b0cd4e2 100644
@@ -294,7 +294,7 @@ endif()
 if(MSVC)
   target_link_libraries(${PROJECT_NAME} BeefySysLib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib LLVMX86Disassembler.lib LLVMMCDisassembler.lib LLVMSupport.lib LLVMX86Info.lib LLVMX86Desc.lib %(AdditionalDependencies) LLVMMC.lib LLVMObject.lib LLVMCore.lib LLVMBitReader.lib LLVMAsmParser.lib LLVMMCParser.lib LLVMCodeGen.lib LLVMTarget.lib LLVMX86CodeGen.lib LLVMScalarOpts.lib LLVMInstCombine.lib LLVMSelectionDAG.lib LLVMProfileData.lib LLVMTransformUtils.lib LLVMAnalysis.lib LLVMX86AsmParser.lib LLVMAsmPrinter.lib LLVMBitWriter.lib LLVMVectorize.lib LLVMipo.lib LLVMInstrumentation.lib LLVMDebugInfoDWARF.lib LLVMDebugInfoPDB.lib LLVMDebugInfoCodeView.lib LLVMGlobalISel.lib LLVMBinaryFormat.lib LLVMAggressiveInstCombine.lib libcurl_a.lib)
 else()
-  target_link_libraries(${PROJECT_NAME} BeefySysLib hunspell pthread dl ${TARGET_LIBS_OS}
+  target_link_libraries(${PROJECT_NAME} BeefySysLib hunspell pthread ffi dl ${TARGET_LIBS_OS}
 
   )
 endif()

--------------------------------- bin/build.sh ---------------------------------
index 3d234bed..68f8be20 100755
@@ -69,7 +69,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
 	LINKOPTS="-Wl,-no_compact_unwind -Wl,-rpath -Wl,@executable_path"
 else
 	LIBEXT=so
-	LINKOPTS="-ldl -lpthread -Wl,-rpath -Wl,\$ORIGIN"
+	LINKOPTS="-ldl -lpthread -lffi -Wl,-rpath -Wl,\$ORIGIN"
 fi
 
 ln -s -f $ROOTPATH/jbuild_d/Debug/bin/libBeefRT_d.a libBeefRT_d.a

Obs: I also noticed that several files have trailing spaces in several lines, maybe the IDE editor isn't trimming lines ?

@mingodad
Copy link
Author

Also there is a simplified/faster way to build on linux (and probably other OSs) using the binary distribution of clan-llvm-13 by adding some conditional macros (only the debugger will not work):

#on `extern` folder
mkdir llvm_project_13_0_1
cd llvm_project_13_0_1
ln -s path_to your_clang-llvm-13 llvm
cd ..
ln -s path_to your_clang-llvm-13 llvm_13_0_1
ln -s path_to your_clang-llvm-13 llvm_rel_13_0_1

I've added this conditional macros but a better name and test should be found:

------------------------- IDEHelper/LinuxDebugger.cpp -------------------------
index 4c1ef527..d442061e 100644
@@ -19,8 +19,10 @@ Beefy::Debugger* CreateDebugger32(DebugManager* debugManager, DbgMiniDump* miniD
 
 Beefy::Debugger* CreateDebugger64(DebugManager* debugManager, DbgMiniDump* miniDump)
 {
+#ifdef NO_X86_DISASM
 	if (gX86Target == NULL)
 		gX86Target = new X86Target();
+#endif
 	return NULL;
 }
 

---------------------------- IDEHelper/Targets.cpp ----------------------------
index 62c24263..433c1407 100644
@@ -6,11 +6,15 @@ USING_NS_BF;
 
 BF_EXPORT void BF_CALLTYPE Targets_Create()
 {
+#ifdef NO_X86_DISASM
 	gX86Target = new X86Target();
+#endif
 }
 
 BF_EXPORT void BF_CALLTYPE Targets_Delete()
 {
+#ifdef NO_X86_DISASM
 	delete gX86Target;
 	gX86Target = NULL;
+#endif
 }
\ No newline at end of file

------------------------------ IDEHelper/X64.cpp ------------------------------
index 4cced4ea..8a481374 100644
@@ -1,3 +1,4 @@
+#ifdef NO_X64_DISASM
 #pragma warning(push)
 #pragma warning(disable:4996)
 #pragma warning(disable:4800)
@@ -1180,4 +1181,6 @@ bool X64CPU::ParseInlineAsmInstructionLLVM(const StringImpl&asmInst, String& out
 										//outError = StrFormat("%s: \"%s\"", diagMessage.c_str(), diagLineContents.c_str());
 
 	return result;
-}
\ No newline at end of file
+}
+
+#endif //NO_X64_DISASM

------------------------------ IDEHelper/X86.cpp ------------------------------
index 518cb331..d485a30c 100644
@@ -1,3 +1,4 @@
+#ifdef NO_X86_DISASM
 #pragma warning(push)
 #pragma warning(disable:4996)
 #pragma warning(disable:4800)
@@ -770,4 +771,6 @@ bool X86CPU::ParseInlineAsmInstructionLLVM(const StringImpl&asmInst, String& out
 		//outError = StrFormat("%s: \"%s\"", diagMessage.c_str(), diagLineContents.c_str());
 
 	return result;
-}
\ No newline at end of file
+}
+
+#endif //NO_X86_DISASM

--------------------------- IDEHelper/X86Target.cpp ---------------------------
index 0812b0f2..7f346b17 100644
@@ -1,3 +1,4 @@
+#ifdef NO_X86_DISASM
 #pragma warning(disable:4996)
 #pragma warning(disable:4800)
 #pragma warning(disable:4244)
@@ -103,4 +104,6 @@ X86Target::~X86Target()
 {
 	delete mX86CPU;
 	delete mX64CPU;
-}
\ No newline at end of file
+}
+
+#endif //NO_X86_DISASM

--------------------------------- bin/build.sh ---------------------------------
index 3d234bed..68f8be20 100755
@@ -69,7 +69,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
 	LINKOPTS="-Wl,-no_compact_unwind -Wl,-rpath -Wl,@executable_path"
 else
 	LIBEXT=so
-	LINKOPTS="-ldl -lpthread -Wl,-rpath -Wl,\$ORIGIN"
+	LINKOPTS="-ldl -lpthread -lffi -Wl,-rpath -Wl,\$ORIGIN"
 fi
 
 ln -s -f $ROOTPATH/jbuild_d/Debug/bin/libBeefRT_d.a libBeefRT_d.a

@marsej
Copy link
Contributor

marsej commented Oct 16, 2022

I noticed that you have done the same mistake I did (unless things have changed). It took me a day or two figure it out.

mkdir llvm_project_13_0_1
should be
mkdir llvm-project_13_0_1

look at what's in the llvm_build.sh to verify.
(in v11 it says if [ ! -d llvm-project_11_0_0 ]; then)

So try changing _ to -
Hope this helps!

@marsej
Copy link
Contributor

marsej commented Oct 16, 2022

under extern things should look like this (following are for v11, I haven't tried v13.0.1 to see if its different):

<DIR>          hunspell
<DIR>          llvm-project_11_0_0
<DIR>          toml
<DIR>          llvm_win64_11_0_0
         1 284 llvm_build.sh
           872 llvm_build.bat
           954 llvm_targets.txt

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