ld: undefined symbol vs ld: undefined reference - gnu

What is the difference between these errors in GNU Binutils ld ?
undefined reference
undefined symbol
I have a good understanding of undefined reference: This occurs for example when the loader cannot find the implementation of a function. I am curious to know the cause of undefined symbol.

e.g. when you do some arithmetic in your linkerscript using a symbol which is not yet defined. In my situation, this is mostly due to typo's.
_syma = 1 ;
_syna += 1 ;
/* error: undefined symbol `_syna' referenced in expression */
or
_syma = 1 ;
_symb = _syna + 1 ;
/* error: undefined symbol `_syna' referenced in expression */
When you assign an output section to an undefined symbol, you get another error:
_syma = 1 ;
.text _syna :
/* error: non constant or forward reference address expression for section .text */
{
*(.text) ;
}

Related

How to compile HSL for IPOPT (after IPOPT)

I use MINGW64 to compile HSL (https://www.hsl.rl.ac.uk/ipopt/) following the redme. However, I end up with an error 2 (Makefile:753). The critical command is
gfortran -shared .libs/libcoinhsl-0.dll.def common/.libs/deps90.o common/.libs/deps.o common/.libs/dump.o mc19/.libs/mc19d.o ma27/.libs/ma27d.o ma28/.libs/ma28d.o ma57/.libs/ma57d.o hsl_ma77/.libs/hsl_ma77d.o hsl_ma77/C/.libs/hsl_ma77d_ciface.o hsl_ma86/.libs/hsl_ma86d.o hsl_ma86/C/.libs/hsl_ma86d_ciface.o hsl_mc68/C/.libs/hsl_mc68i_ciface.o hsl_ma97/.libs/hsl_ma97d.o hsl_ma97/C/.libs/hsl_ma97d_ciface.o loadmetis/.libs/loadmetis.o -L/mingw64/lib/ -lopenblas -lpthread -lgfortran -O2 -Wl,-rpath -Wl,/mingw64/lib -o .libs/libcoinhsl-0.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libcoinhsl.dll.a
The output is
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: common/.libs/deps90.o:C:\msys64\home\user\hsl_solo\coinhsl/common/deps90.f90:17672: undefined reference to `metis_nodend_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: common/.libs/deps90.o: in function `__hsl_mc68_integer_MOD_mc68_order_integer':
C:\msys64\home\user\hsl_solo\coinhsl/common/deps90.f90:17454: undefined reference to `metis_nodend_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ma57/.libs/ma57d.o: in function `ma57ad_':
C:\msys64\home\user\hsl_solo\coinhsl/ma57/ma57d.f:469: undefined reference to `metis_nodend_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\home\user\hsl_solo\coinhsl/ma57/ma57d.f:682: undefined reference to `metis_nodend_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\home\user\hsl_solo\coinhsl/ma57/ma57d.f:618: undefined reference to `metis_nodend_'
collect2.exe: error: ld returned 1 exit status
As I am not that experienced with compiling software, does anyone have an idea how I can get this error fixed?
Symbol metis_nodend_ belongs to Metis.
The metis_nodend_ symbol needs to be resolved either by linking against a Metis library (you might need to specify where to find that via some flags for configure), by a function of that name that loads the Metis library at runtime (that is what loadmetis tries to do), or by a dummy function of that name that does nothing (thats what older versions of HSL used to do).
The loadmetis of HSL is implemented in C and defines a function METIS_NODEND:
void METIS_NODEND(int *nvtxs, int *xadj, int *adjncy, int *numflag,
int *options, int *perm, int *iperm) {
....
So the problem is probably that the naming conventions do not match, i.e., the functionname in the C object does not match the functionname that the Fortran objects expect.
Try changing METIS_NODEND to metis_nodend or metis_nodend_ in loadmetis.c.
Or try the buildsystem from https://github.com/coin-or-tools/ThirdParty-HSL/

BZIP2 linking error with Cygwin64

I encounter the following linking error when attempting to use in Cygwin64. My PATH accounts for the location of libbz2.a and libbz2.dll.
$ gcc -lbz2 bzlibExample.c -o bzlibExample
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x18b): undefined reference to `BZ2_bzWriteOpen'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x18b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `BZ2_bzWriteOpen'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x1ef): undefined reference to `BZ2_bzWrite'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x1ef): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `BZ2_bzWrite'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x233): undefined reference to `BZ2_bzWriteClose'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x233): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `BZ2_bzWriteClose'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x2bb): undefined reference to `BZ2_bzWriteClose'
/tmp/ccz9P7fm.o:bzlibExample.c:(.text+0x2bb): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `BZ2_bzWriteClose'
collect2: error: ld returned 1 exit status
Any assistance is appreciated.

How to resolve the Undefined References?

In trying to making a file on ubuntu using terminal, I am getting a series of these undefined reference statements:
Node.cpp:(.text+0x978): undefined reference to glLineWidth'
Node.cpp:(.text+0x996): undefined reference toglPushMatrix'
Node.cpp:(.text+0x9fb): undefined reference to glTranslatef'
Node.cpp:(.text+0xa0b): undefined reference toglColor3fv'
.
.
Parser.cpp:(.text+0x1a69): undefined reference to wxLogVerbose(wchar_t const*, ...)'
Parser.cpp:(.text+0x1a8e): undefined reference towxLogVerbose(wchar_t const*, ...)'
Parser.cpp:(.text+0x1e4d): undefined reference to `wxLogError(wchar_t const*, ...)'
collect2: error: ld returned 1 exit status
make: * [aqua3d] Error 1**
Kindly let me know what is solution to this.
FYI, I've already installed freeglut, libgtk and libwxgtk.

OCaml Compiler on Windows - compiling module error. (i686-w64-mingw32-as)

I'm using Windows 7 64x and in my next semester, I'll have OCaml as main language in one of my lectures and I am more of a "Windows" person (I have windows version and cygwin-based version). So I decided to go over this tutorial.
Now here's the problem:
I've created files amodule.ml and bmodule.ml as specified in the link. However, when I'm trying to execute following lines on the commandline:
ocamlopt -c amodule.ml
I get following error:
'i686-w64-mingw32-as' is not recognized as an internal or external command, operable program or batch file.
File "amodule.ml", line 1:
Error: Assembler error, input left in file C:\Users\Devate\AppData\Local\Temp\camlasm0d9121.s
And almost the same error comes with bmodule.ml and using the last line:
ocamlopt -o hello amodule.cmx bmodule.cmx
After doing that - I get two new files named amodule.cmi and bmodule.cmi.
However, if I try doing compiling using cygwin version, I get no errors (I get both amodule.cmi and amodule.cmx - same with bmodule).
However with last line in cygwin I get tons of errors:
ocamlopt -o hello amodule.cmx bmodule.cmx
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/std_exit.o' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/stdlib.a(pervasives.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(ints.o)' is incompatible with
i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(i386.o)' is incompatible with
i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(fail.o)' is incompatible with
i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(io.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(str.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(minor_gc.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(intern.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(compare.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(floats.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(sys.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(extern.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(memory.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(callback.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(startup.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(alloc.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(custom.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(roots.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(signals_asm.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(backtrace.o)' is incompatible
with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(printexc.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(signals.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(weak.o)' is incompatible with
i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(gc_ctrl.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(major_gc.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(misc.o)' is incompatible with
i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(finalise.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(md5.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(freelist.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(win32.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(globroots.o)' is incompatible
with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(parsing.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(debugger.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `C:\OCaml\lib/libasmrun.a(compact.o)' is incompatible with i386:x86-64 output
/tmp/camlstartup942177.o:fake:(.text+0x5): undefined reference to `camlPervasives__entry'
/tmp/camlstartup942177.o:fake:(.text+0x5): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `camlPervasives__entry'
/tmp/camlstartup942177.o:fake:(.text+0xc): undefined reference to `caml_globals_inited'
/tmp/camlstartup942177.o:fake:(.text+0xc): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `caml_globals_inited'
/tmp/camlstartup942177.o:fake:(.text+0x1c): undefined reference to `caml_globals_inited'
/tmp/camlstartup942177.o:fake:(.text+0x1c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `caml_globals_inited'
/tmp/camlstartup942177.o:fake:(.text+0x2c): undefined reference to `caml_globals_inited'
/tmp/camlstartup942177.o:fake:(.text+0x2c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `caml_globals_inited'
/tmp/camlstartup942177.o:fake:(.text+0x35): undefined reference to `camlStd_exit__entry'
/tmp/camlstartup942177.o:fake:(.text+0x35): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `camlStd_exit__entry'
/tmp/camlstartup942177.o:fake:(.text+0x3c): undefined reference to `caml_globals_inited'
/tmp/camlstartup942177.o:fake:(.text+0x3c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `caml_globals_inited'
/tmp/camlstartup942177.o:fake:(.text+0x5e): undefined reference to `caml_young_limit'
/tmp/camlstartup942177.o:fake:(.text+0x5e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `caml_young_limit'
/tmp/camlstartup942177.o:fake:(.text+0x9e): undefined reference to `caml_call_gc'
/tmp/camlstartup942177.o:fake:(.text+0x9e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `caml_call_gc'
/tmp/camlstartup942177.o:fake:(.text+0xee): undefined reference to `caml_young_limit'
/tmp/camlstartup942177.o:fake:(.text+0xee): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `caml_young_limit'
/tmp/camlstartup942177.o:fake:(.text+0x12e): undefined reference to `caml_call_gc'
/tmp/camlstartup942177.o:fake:(.text+0x12e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `caml_call_gc'
/tmp/camlstartup942177.o:fake:(.text+0x16e): undefined reference to `caml_young_limit'
/tmp/camlstartup942177.o:fake:(.text+0x16e): additional relocation overflows omitted from the output
/tmp/camlstartup942177.o:fake:(.text+0x1a3): undefined reference to `caml_call_gc'
/tmp/camlstartup942177.o:fake:(.text+0x1ee): undefined reference to `caml_young_limit'
/tmp/camlstartup942177.o:fake:(.text+0x22e): undefined reference to `caml_call_gc'
/tmp/camlstartup942177.o:fake:(.text+0x26e): undefined reference to `caml_young_limit'
/tmp/camlstartup942177.o:fake:(.text+0x2a3): undefined reference to `caml_call_gc'
/tmp/camlstartup942177.o:fake:(.text+0x2de): undefined reference to `caml_young_limit'
/tmp/camlstartup942177.o:fake:(.text+0x313): undefined reference to `caml_call_gc'
/tmp/camlstartup942177.o:fake:(.data+0x2b8): undefined reference to `camlPervasives'
/tmp/camlstartup942177.o:fake:(.data+0x2d0): undefined reference to `camlStd_exit'
/tmp/camlstartup942177.o:fake:(.data+0x3d8): undefined reference to `camlPervasives__data_begin'
/tmp/camlstartup942177.o:fake:(.data+0x3e0): undefined reference to `camlPervasives__data_end'
/tmp/camlstartup942177.o:fake:(.data+0x408): undefined reference to `camlStd_exit__data_begin'
/tmp/camlstartup942177.o:fake:(.data+0x410): undefined reference to `camlStd_exit__data_end'
/tmp/camlstartup942177.o:fake:(.data+0x430): undefined reference to `camlPervasives__code_begin'
/tmp/camlstartup942177.o:fake:(.data+0x438): undefined reference to `camlPervasives__code_end'
/tmp/camlstartup942177.o:fake:(.data+0x460): undefined reference to `camlStd_exit__code_begin'
/tmp/camlstartup942177.o:fake:(.data+0x468): undefined reference to `camlStd_exit__code_end'
/tmp/camlstartup942177.o:fake:(.data+0x480): undefined reference to `caml_system__frametable'
/tmp/camlstartup942177.o:fake:(.data+0x488): undefined reference to `camlPervasives__frametable'
/tmp/camlstartup942177.o:fake:(.data+0x4a0): undefined reference to `camlStd_exit__frametable'
bmodule.o:fake:(.text+0xc): undefined reference to `camlPervasives__print_endline_1257'
amodule.o:fake:(.text+0x8): undefined reference to `camlPervasives__print_endline_1257'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.text+0x1b5): undefined reference to `_caml_exn_End_of_file'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.text+0x493): undefined reference to `_caml_exn_Failure'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.text+0x4d3): undefined reference to `_caml_exn_Invalid_argument'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.text+0xa76): undefined reference to `_caml_exn_End_of_file'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.text+0xb18): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x184): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x194): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x1bc): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x2b0): undefined reference to `_caml_curry4'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x2c0): undefined reference to `_caml_curry4'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x2d0): undefined reference to `_caml_curry4'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x2f8): undefined reference to `_caml_curry3'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x320): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x330): undefined reference to `_caml_curry4'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x340): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x374): undefined reference to `_caml_curry3'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x384): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x3dc): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x404): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x414): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x448): undefined reference to `_caml_curry2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x458): more undefined references to `_caml_curry2' follow
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x524): undefined reference to `_caml_curry3'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7c4): undefined reference to `_fmod'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7cc): undefined reference to `_floor'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7d0): undefined reference to `_ceil'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7d4): undefined reference to `_tanh'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7d8): undefined reference to `_tan'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7dc): undefined reference to `_sqrt'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7e0): undefined reference to `_sinh'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7e4): undefined reference to `_sin'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7ec): undefined reference to `_log10'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7f0): undefined reference to `_log'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7f4): undefined reference to `_cosh'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x7f8): undefined reference to `_cos'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x800): undefined reference to `_atan2'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x804): undefined reference to `_atan'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x808): undefined reference to `_asin'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x80c): undefined reference to `_acos'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x814): undefined reference to `_exp'
C:\OCaml\lib/stdlib.a(pervasives.o):fake:(.data+0x818): undefined reference to `_pow'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0x3f9): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0x429): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0x457): undefined reference to `_atoi'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0x560): undefined reference to `_sprintf'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0x57c): undefined reference to `_sprintf'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0x86c): undefined reference to `_sprintf'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0xa29): undefined reference to `___divdi3'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0xaa6): undefined reference to `___moddi3'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0xde3): undefined reference to `_sprintf'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0xe56): undefined reference to `___udivdi3'
C:\OCaml\lib/libasmrun.a(ints.o):ints.c:(.text+0x131a): undefined reference to `_sprintf'
C:\OCaml\lib/libasmrun.a(i386.o):fake:(.text+0x119): undefined reference to `_caml_program'
C:\OCaml\lib/libasmrun.a(i386.o):fake:(.text+0x211): undefined reference to `_caml_apply2'
C:\OCaml\lib/libasmrun.a(i386.o):fake:(.text+0x231): undefined reference to `_caml_apply3'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x219): undefined reference to `_caml_exn_Failure'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x230): undefined reference to `_caml_exn_Invalid_argument'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x23f): undefined reference to `_caml_bucket_Out_of_memory'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x24e): undefined reference to `_caml_bucket_Stack_overflow'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x265): undefined reference to `_caml_exn_Sys_error'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x274): undefined reference to `_caml_exn_End_of_file'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x283): undefined reference to `_caml_exn_Division_by_zero'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x292): undefined reference to `_caml_exn_Not_found'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x2a1): undefined reference to `_caml_exn_Sys_blocked_io'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x2d7): undefined reference to `_caml_exn_Invalid_argument'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x326): undefined reference to `_caml_exn_Match_failure'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x32d): undefined reference to `_caml_exn_Assert_failure'
C:\OCaml\lib/libasmrun.a(fail.o):fail.c:(.text+0x334): undefined reference to `_caml_exn_Undefined_recursive_module'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0xbc): undefined reference to `_write'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x149): undefined reference to `__lseeki64'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x1d9): undefined reference to `_close'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x249): undefined reference to `__lseeki64'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x270): undefined reference to `__lseeki64'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x351): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x464): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x47b): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x4b4): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x554): undefined reference to `__lseeki64'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x5c8): undefined reference to `_read'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x5f8): undefined reference to `_read'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x71d): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x73a): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x786): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x882): undefined reference to `__lseeki64'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x90c): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0xafd): undefined reference to `_close'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x1284): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x12aa): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(io.o):io.c:(.text+0x1308): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(str.o):str.c:(.text+0x41d): undefined reference to `_memcmp'
C:\OCaml\lib/libasmrun.a(str.o):str.c:(.text+0x52e): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(str.o):str.c:(.text+0x560): undefined reference to `_memset'
C:\OCaml\lib/libasmrun.a(str.o):str.c:(.text+0x589): undefined reference to `_setlocale'
C:\OCaml\lib/libasmrun.a(str.o):str.c:(.text+0x5a2): undefined reference to `__imp__isprint'
C:\OCaml\lib/libasmrun.a(minor_gc.o):minor_gc.c:(.text+0x56d): undefined reference to `_free'
C:\OCaml\lib/libasmrun.a(minor_gc.o):minor_gc.c:(.text+0x6b7): undefined reference to `_realloc'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x13): undefined reference to `_free'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x241): undefined reference to `_sprintf'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x2ce): undefined reference to `_malloc'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x2f9): undefined reference to `_realloc'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x5c3): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x7b7): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x89d): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x9f2): undefined reference to `_memcmp'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x1227): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(intern.o):intern.c:(.text+0x13d7): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(compare.o):compare.c:(.text+0x13): undefined reference to `_free'
C:\OCaml\lib/libasmrun.a(compare.o):compare.c:(.text+0x2a5): undefined reference to `_memcmp'
C:\OCaml\lib/libasmrun.a(compare.o):compare.c:(.text+0x430): undefined reference to `_strcmp'
C:\OCaml\lib/libasmrun.a(compare.o):compare.c:(.text+0x519): undefined reference to `_malloc'
C:\OCaml\lib/libasmrun.a(compare.o):compare.c:(.text+0x548): undefined reference to `_realloc'
C:\OCaml\lib/libasmrun.a(floats.o):floats.c:(.text+0x9f): undefined reference to `_atoi'
C:\OCaml\lib/libasmrun.a(floats.o):floats.c:(.text+0xe1): undefined reference to `_atoi'
C:\OCaml\lib/libasmrun.a(floats.o):floats.c:(.text+0x121): undefined reference to `_sprintf'
C:\OCaml\lib/libasmrun.a(floats.o):floats.c:(.text+0x1a6): undefined reference to `_sprintf'
C:\OCaml\lib/libasmrun.a(floats.o):floats.c:(.text+0x267): undefined reference to `___strtod'
C:\OCaml\lib/libasmrun.a(floats.o):floats.c:(.text+0x314): undefined reference to `___strtod'
C:\OCaml\lib/libasmrun.a(weak.o):weak.c:(.text+0x41d): undefined reference to `_memmove'
C:\OCaml\lib/libasmrun.a(major_gc.o):major_gc.c:(.text+0xb8): undefined reference to `_realloc'
C:\OCaml\lib/libasmrun.a(major_gc.o):major_gc.c:(.text+0xb39): undefined reference to `_malloc'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x16f): undefined reference to `_fwrite'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x1bb): undefined reference to `_realloc'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x204): undefined reference to `__imp___findfirst'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x287): undefined reference to `_malloc'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x2a2): undefined reference to `_memcpy'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x2b9): undefined reference to `_strcpy'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x2d1): undefined reference to `__imp___findnext'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x2e3): undefined reference to `__imp___findclose'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x5ae): undefined reference to `_strcpy'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x616): undefined reference to `_strcpy'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x68c): undefined reference to `_flexdll_dlopen'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x6a3): undefined reference to `_flexdll_dump_exports'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x6a8): undefined reference to `__imp___iob'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x6b3): undefined reference to `_fflush'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x6c9): undefined reference to `_flexdll_dlclose'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x73b): undefined reference to `_signal'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x75b): undefined reference to `__imp__SetConsoleCtrlHandler#8'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x7a9): undefined reference to `_malloc'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x863): undefined reference to `_strcpy'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x8bd): undefined reference to `__imp___findfirst'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x93d): undefined reference to `_strcpy'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x961): undefined reference to `__imp___findnext'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x96e): undefined reference to `__imp___findclose'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x98e): undefined reference to `__imp__SetUnhandledExceptionFilter#4'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x9aa): undefined reference to `__imp__GetSystemTimeAsFileTime#4'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x9ba): undefined reference to `__imp__QueryPerformanceCounter#4'
C:\OCaml\lib/libasmrun.a(win32.o):win32.c:(.text+0x9d0): undefined reference to `__imp__GetCurrentProcessId#0'
C:\OCaml\lib/libasmrun.a(parsing.o):parsing.c:(.text+0x4a2): undefined reference to `_fprintf'
C:\OCaml\lib/libasmrun.a(parsing.o):parsing.c:(.text+0x570): undefined reference to `__imp___iob'
C:\OCaml\lib/libasmrun.a(parsing.o):parsing.c:(.text+0x57b): undefined reference to `_fprintf'
C:\OCaml\lib/libasmrun.a(compact.o):compact.c:(.text+0x50d): undefined reference to `_memmove'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../lib/libcygwin.a(libcmain.o): In function `main':
/usr/src/debug/cygwin-1.7.31-2/winsup/cygwin/lib/libcmain.c:39: undefined reference to `WinMain'
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking
And I have no idea what to do.
If you want to learn OCaml, do not use Windows. No matter whether you are a Windows person or not. Period.
With that said, i686-w64-mingw32-as is an assembler and it is missing. You must read OCaml's instruction README.win32 carefully and install required softwares.
For the trouble of Cygwin version, I guess you are trying to link your Cygwin object files with MinGW OCaml installation. This wont work at all. Maybe your Cygwin OCaml is totally confused by the env var for MinGW OCaml.
I repeat. OCaml in Windows has so many pit falls for new leaners. Just avoid it.

Haskell FFI stack size with a C++ shared library

I am trying to send a very large amount of data, on the order of several Gigabytes to Haskell via a shared library. Everything seems to work fine up to a point, but I eventually get the error:
Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize' to increase it.
So basically, my question is: How do I increase the Haskell stack size?
I have tried:
1) Passing the appropriate -rtsopts flags to the linker when building the shared library -- No luck, but this is expected because I am using the Haskell as a shared library.
2) Calling hs_init with the RTS flags as described in this link:
Haskell User Guide FFI/GHC...which did not work either.
int argc = 2;
char *argv[] = { "+RTS", "-K100M", NULL };
char **pargv = argv;
// Initialize Haskell runtime
hs_init(&argc, &pargv);
Basically I think that these arguments are also ignored because I am not using a Haskell main, which is also described in the user guide link I provided.
NOTE: I have also tried this approach adding a "-RTS" to the list before NULL and increasing argc but it made no difference.
3) I suspect that the true solution to this problem would be by following section 8.2.1.1 in the given link and making the special call to hs_init_ghc as so:
#include "HsFFI.h"
#include "Rts.h"
RtsConfig conf = defaultRtsConfig;
conf.rts_opts_enabled = RtsOptsAll;
hs_init_ghc(&argc, &argv, conf);
However when I try to do this as described in the guide, my C code that calls:
hs_init_ghc
will NOT compile due to a whole bunch of errors which I have pasted into the bottom of this question. It seems that including RTS.h will not compile, but I am following the example exactly, and compiling with:
ghc -c foo.cpp
I am wondering if anyone has any advice on how to get around this compilation error or to set the stack-size to a bigger value when using the Haskell as a shared library from C++?
I have also tried setting the corresponding environment variable, which also did not work. I even got a message saying it will be ignored.
I am using GHC version 7.4.1
Thanks very much for your help.
--JL
Compilation errors are:
>
In file included from /usr/lib/ghc/include/Rts.h:222:0:
0, from foo.cpp:6:
/usr/lib/ghc/include/rts/storage/Block.h:227:26:
error: expected ‘,’ or ‘...’ before ‘new’
dbl_link_replace(bdescr *new, bdescr *old, bdescr **list)
^
/usr/lib/ghc/include/rts/storage/Block.h: In function ‘void dbl_link_replace(bdescr*)’:
/usr/lib/ghc/include/rts/storage/Block.h:229:8:
error: expected type-specifier before ‘->’ token
new->link = old->link;
^
/usr/lib/ghc/include/rts/storage/Block.h:229:8:
error: expected ‘;’ before ‘->’ token
/usr/lib/ghc/include/rts/storage/Block.h:230:8:
error: expected type-specifier before ‘->’ token
new->u.back = old->u.back;
^
/usr/lib/ghc/include/rts/storage/Block.h:230:8:
error: expected ‘;’ before ‘->’ token
/usr/lib/ghc/include/rts/storage/Block.h:231:9:
error: ‘old’ was not declared in this scope
if (old->link) {
^
/usr/lib/ghc/include/rts/storage/Block.h:232:32:
error: expected type-specifier before ‘;’ token
old->link->u.back = new;
^
/usr/lib/ghc/include/rts/storage/Block.h:234:9:
error: ‘old’ was not declared in this scope
if (old->u.back) {
^
/usr/lib/ghc/include/rts/storage/Block.h:235:32:
error: expected type-specifier before ‘;’ token
old->u.back->link = new;
^
/usr/lib/ghc/include/rts/storage/Block.h:237:10:
error: ‘list’ was not declared in this scope
*list = new;
^
/usr/lib/ghc/include/rts/storage/Block.h:237:20:
error: expected type-specifier before ‘;’ token
*list = new;
^
In file included from /usr/lib/ghc/include/Rts.h:218:0:
0,
from foo.cpp:6:
/usr/lib/ghc/include/rts/storage/ClosureMacros.h: In function ‘rtsBool
More compile errors removed...but available upon request.

Resources