cpp file "undefined reference to" #3693
-
Hello, I'm trying scala-native and doing some testing. How do I add If I create a int add3(int i) {
return i + 3;
} Everything works normally. But if I take the same file and rename it to [error] /usr/bin/ld: /mnt/data/sources/scala/native/app/target/scala-3.3.1/native/6.ll.o: in function `_SM5Main$D4mainLAL16java.lang.String_uEO':
[error] 6.ll:(.text+0xf797): undefined reference to `add3'
[error] /usr/bin/ld: 6.ll:(.text+0xf7a3): undefined reference to `cprintln'
[error] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[error] Failed to link /mnt/data/sources/scala/native/app/target/scala-3.3.1/app-out
[error] (Compile / nativeLink) Failed to link /mnt/data/sources/scala/native/app/target/scala-3.3.1/app-out
[error] Total time: 20 s, completed Jan 18, 2024, 5:26:44 PM
I didn't find any instructions in the documentation about this. Am I missing something? My scala code:
I'm already try add |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
You need to wrap your function with |
Beta Was this translation helpful? Give feedback.
-
OMG this work! Thank you very much! |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm advancing a little further in my Scala-Native studies. So I decided to make a simplified wrap version of boost-beast. When I used a single file error: no member named 'optional' in namespace 'std' I already tried adding [error] error: invalid argument '-std=c++17' not allowed with 'C' If it helps, here is the project source: https://github.com/mobilemindtec/scala-beast What am I missing? |
Beta Was this translation helpful? Give feedback.
-
I have a strange situation. When I configure the server to run multithread, the application freezes. Something related to the callback provided by scala. My test callback function is "pure", it doesn't access any shared resources, It just creates the response, which is a struct. No error occurs, the server just stops responding. When there is no scala callback, the server does not freeze. Will this be a limitation of the current version? Any idea? Thanks! |
Beta Was this translation helpful? Give feedback.
-
This is beyond my knowledge, but it really seems to be an issue related to concurrent memory allocation: Thread 1 "http-native-out" received signal SIGSEGV, Segmentation fault.
__memset_avx2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S:244
Downloading source file /usr/src/debug/glibc/glibc/string/../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
244 VMOVU %VMM(0), (%rdi)
(gdb) where
#0 __memset_avx2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S:244
#1 0x00005555557b80d1 in _SM21java.lang.StackTrace$D28currentStackTrace$$anonfun$1L36scala.collection.mutable.ArrayBufferL29scala.scalanative.unsafe.ZoneuEPT21java.lang.StackTrace$ ()
#2 0x000055555576bfb5 in _SM31java.lang.StackTrace$$$Lambda$2D9applyVoidL16java.lang.ObjectuEO ()
#3 0x00005555557410e8 in _SM34scala.runtime.function.JProcedure1D5applyL16java.lang.ObjectL16java.lang.ObjectEO ()
#4 0x000055555576a534 in _SM30scala.scalanative.unsafe.Zone$D5applyL15scala.Function1L16java.lang.ObjectEO ()
#5 0x00005555557b7beb in _SM21java.lang.StackTrace$D17currentStackTraceLAL27java.lang.StackTraceElement_EO ()
#6 0x00005555557b69f3 in _SM19java.lang.ThrowableD16fillInStackTraceL19java.lang.ThrowableEO ()
#7 0x000055555576ec1b in _SM34scala.scalanative.runtime.package$D14throwClassCastR_R_nEO ()
#8 0x000055555577e64a in _SM16httpserver.Main$D11handlerSyncL28scala.scalanative.unsafe.PtrL28scala.scalanative.unsafe.PtrEO ()
#9 0x000055555577e7c7 in _SM16httpserver.Main$D36runCSyncServer$$anonfun$1$$anonfun$1L28scala.scalanative.unsafe.PtrL28scala.scalanative.unsafe.PtrEPT16httpserver.Main$ ()
#10 0x000055555573b07c in _SM26httpserver.Main$$$Lambda$2G17$extern$forwarder ()
#11 0x000055555565cfbd in httpserver::http_handler::dispatch (this=0x5555558e43c0, req=0x5555558e4930)
at /mnt/data/sources/scala/native/http-native/target/scala-3.3.1/native/native-code-classes-0/scala-native/http_handler.cpp:37
#12 0x00005555556b53be in httpserver::http_session::handle_request<boost::beast::http::basic_string_body<char, std::char_traits<char>, std::allocator<char> >, std::allocator<char> > (this=0x5555558e26d0, req=...)
at /mnt/data/sources/scala/native/http-native/target/scala-3.3.1/native/native-code-classes-0/scala-native/httpserver.cpp:345
#13 0x00005555556885d5 in httpserver::http_session::on_read (this=0x5555558e26d0, ec=..., bytes_transferred=62)
at /mnt/data/sources/scala/native/http-native/target/scala-3.3.1/native/native-code-classes-0/scala-native/httpserver.cpp:89
|
Beta Was this translation helpful? Give feedback.
You need to wrap your function with
extern "C"
. See https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c