digitalmars.D - linking in linux
- llee (8/8) Sep 27 2007 I'm having problems calling functions that are defined in other .d files...
- BCS (10/34) Sep 27 2007 A little source code would help (the d file for starters). My only guess...
- Regan Heath (3/31) Sep 28 2007 And the command line used to compile and link.
- llee (23/23) Sep 28 2007 I wrote a test program to isolate the problem. The following program (pr...
- Steven Schveighoffer (5/26) Sep 28 2007 try dmd program.d test.d
- Steven Schveighoffer (13/14) Sep 28 2007 nm libxyz.a
- BCS (2/29) Sep 28 2007 cool, I'll have to remember that
I'm having problems calling functions that are defined in other .d files under linux. Whenever I make a function call to a function that is defined in another .d file, the linker (ld) returns an error (exit code 1) saying that the referenced function is undefined. I have a program that is trying to call a function named distorm_decode (...). This function is declared in the file distorm.d. The function is defined in a file named distorm.c. This file was compiled using the gcc compiler and stored in a .a archive (library) using ar. When I try to compile my program ld returns the following error: d_disassembler.d:(.gnu.linkonce.t_Dmain + 0x10c): undefined reference to 'distorm_decode' collect2: ld returned 1 exit status --errorlevel 1 This is not the first time that I've encountered this problem. Other programs have also failed to compile, even when the function is defined in another d module. Any help would be appreciated.
Sep 27 2007
Reply to llee,I'm having problems calling functions that are defined in other .d files under linux. Whenever I make a function call to a function that is defined in another .d file, the linker (ld) returns an error (exit code 1) saying that the referenced function is undefined. I have a program that is trying to call a function named distorm_decode (...). This function is declared in the file distorm.d. The function is defined in a file named distorm.c. This file was compiled using the gcc compiler and stored in a .a archive (library) using ar. When I try to compile my program ld returns the following error: d_disassembler.d:(.gnu.linkonce.t_Dmain + 0x10c): undefined reference to 'distorm_decode' collect2: ld returned 1 exit status --errorlevel 1 This is not the first time that I've encountered this problem. Other programs have also failed to compile, even when the function is defined in another d module. Any help would be appreciated.A little source code would help (the d file for starters). My only guess from what you have sad would be that the declaration is wrong. Two things come to mind: Are you sure that the function is being compiled as a C function and not a C++ function? Did you use extern(C) in the d file? to check that one.
Sep 27 2007
BCS wrote:Reply to llee,And the command line used to compile and link. ReganI'm having problems calling functions that are defined in other .d files under linux. Whenever I make a function call to a function that is defined in another .d file, the linker (ld) returns an error (exit code 1) saying that the referenced function is undefined. I have a program that is trying to call a function named distorm_decode (...). This function is declared in the file distorm.d. The function is defined in a file named distorm.c. This file was compiled using the gcc compiler and stored in a .a archive (library) using ar. When I try to compile my program ld returns the following error: d_disassembler.d:(.gnu.linkonce.t_Dmain + 0x10c): undefined reference to 'distorm_decode' collect2: ld returned 1 exit status --errorlevel 1 This is not the first time that I've encountered this problem. Other programs have also failed to compile, even when the function is defined in another d module. Any help would be appreciated.A little source code would help (the d file for starters).
Sep 28 2007
I wrote a test program to isolate the problem. The following program (program.d) calls a function named test_function() that is defined in test.d. test.d is displayed after it. When I try to compile the the program I receive an error. program.d: ------ import test; void main () { test_function (); } test.d: ------ import std.cstream; void test_function () { dout.writeLine ("test function called."); { Compilation: ------ dmd program.d ... program.o: (.data+0x30): undefined reference to '_D11test_module12_ModuleInfoZ' program.o (.gnu.linkonce.t_Dmain+0x4): undefined reference to '_D11test_module13test_functionFZv' collect2: ld returned 1 exit status --errorlevel 1
Sep 28 2007
"llee" <llee goucher.edu> wrote in message news:fdj3h4$m3j$1 digitalmars.com...I wrote a test program to isolate the problem. The following program (program.d) calls a function named test_function() that is defined in test.d. test.d is displayed after it. When I try to compile the the program I receive an error. program.d: ------ import test; void main () { test_function (); } test.d: ------ import std.cstream; void test_function () { dout.writeLine ("test function called."); { Compilation: ------ dmd program.dtry dmd program.d test.d The linker can't find test.o because you didn't tell it to compile it. -Steve
Sep 28 2007
"BCS" <ao pathlink.com> wrote in message news:ce0a334323bfe8c9cf6333c514f2 news.digitalmars.com...nm libxyz.a This will list all the symbols defined in libxyz.a. You can do: nm libxyz.a | grep distorm To see if the name is mangled. You can also do: nm -C libxyz.a To have nm demangle the symbols for you You can also do: nm -D libxyz.so to list symbols in a dynamic library. -Steve
Sep 28 2007
Reply to Steven,"BCS" <ao pathlink.com> wrote in message news:ce0a334323bfe8c9cf6333c514f2 news.digitalmars.com...cool, I'll have to remember thatnm libxyz.a This will list all the symbols defined in libxyz.a. You can do: nm libxyz.a | grep distorm To see if the name is mangled. You can also do: nm -C libxyz.a To have nm demangle the symbols for you You can also do: nm -D libxyz.so to list symbols in a dynamic library. -Steve
Sep 28 2007