User forums > Using Code::Blocks

Make a program that use a .so

<< < (2/2)

oBFusCATed:
Then read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

clros:

--- Quote from: oBFusCATed on November 29, 2010, 09:20:12 am ---Then read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

--- End quote ---

My command line is:

g++ -L/home/claudio/Scrivania/ProvaShared/bin/Release  -o bin/Release/TestShared obj/Release/main.o   -s  -lProvaShared
obj/Release/main.o: In function `main'

My .so is called "libProvaShared.so"

This invocation sems to be right.
But I have this error:

main.cpp:(.text+0x3c): undefined reference to `SampleFunction1()'
main.cpp:(.text+0x41): undefined reference to `SampleFunction1()'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)

2 errors, 0 warn

This is my simple program:

--- Code: ---#include <iostream>
//prototype
int SampleFunction1();

int main()
{
    SampleFunction1();
    std::cout <<SampleFunction1()<< endl;
    return 0;
}
 
--- End code ---

Jenna:
How did you declare your function ?
If you use the sample shared library created by the wizard as it is (with extern "C" around the functions implementation), you also have to add it (extern "C") to the declaration in the header file (or wherever you declared it), or leave the extern "C" away (in both places), if you use it as pure c++.

clros:

--- Quote from: jens on November 29, 2010, 06:58:31 pm ---How did you declare your function ?
If you use the sample shared library created by the wizard as it is (with extern "C" around the functions implementation), you also have to add it (extern "C") to the declaration in the header file (or wherever you declared it), or leave the extern "C" away (in both places), if you use it as pure c++.

--- End quote ---

It now work!!
Thanks!!  :)

Navigation

[0] Message Index

[*] Previous page

Go to full version