home › Forums › # Technical Support › Linking Fuzzylite library with C code
- This topic has 2 replies, 2 voices, and was last updated 9 years, 1 month ago by
Unknown.
-
AuthorPosts
-
August 20, 2014 at 02:19 #1382
Unknown
MemberHi,
I am trying to link the fuzzylite c++ library with my c code.
So I have the example fuzzylite program in gmm.cpp
extern "C" int func1() { fl.Engine () ... ... }
I compiled it with following command
g++ gmm.cpp -Ifuzzylite -Lfuzzylite/bin -lfuzzylite -c -o gmm.o
I have created one gmm.h header to export func1 to .c code.
#ifndef __GMM_H #define __GMM_H #ifdef __cplusplus extern "C" { #endif int func2(); #ifdef __cplusplus } #endif #endif
Now I have a c program which is calling to func1() from main()
#include <stdio.h> #include "gmm.h" int main() { func1(); }
compiling it with :
gcc -c gaurav.c -o gaurav.
oSo when I try to create a final binary
g++ -Ifuzzylite -Lfuzzylite/bin -lfuzzylite gmm.o gaurav.o -o gaurav
It is giving me this error:
fuzzylite/gmm.o: In function
func1()’:
gmm.cpp:(.text+0x7f): undefined reference to `fl::Engine::Engine(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’
gmm.cpp:(.text+0xfb): undefined reference to `fl::InputVariable::InputVariable(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double)’
gmm.cpp:(.text+0x206): undefined reference to `fl::Triangle::Triangle(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double, double)’
gmm.cpp:(.text+0x2af): undefined reference to `fl::Triangle::Triangle(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double, double)’
gmm.cpp:(.text+0x348): undefined reference to `fl::Triangle::Triangle(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double, double)’
gmm.cpp:(.text+0x3e6): undefined reference to `fl::OutputVariable::OutputVariable(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double)’
gmm.cpp:(.text+0x501): undefined reference to `fl::Triangle::Triangle(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double, double)’
gmm.cpp:(.text+0x596): undefined reference to `fl::Triangle::Triangle(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double, double)’
gmm.cpp:(.text+0x627): undefined reference to `fl::Triangle::Triangle(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double, double)’
gmm.cpp:(.text+0x6ad): undefined reference to `fl::RuleBlock::RuleBlock(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’
gmm.cpp:(.text+0x710): undefined reference to `fl::Rule::parse(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, fl::Engine const*)’
gmm.cpp:(.text+0x77c): undefined reference to `fl::Rule::parse(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, fl::Engine const*)’
gmm.cpp:(.text+0x7e8): undefined reference to `fl::Rule::parse(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, fl::Engine const*)’
gmm.cpp:(.text+0xad6): undefined reference to `fl::Exception::Exception(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’
gmm.cpp:(.text+0xb33): undefined reference to `fl::Exception::~Exception()’
gmm.cpp:(.text+0xb3f): undefined reference to `typeinfo for fl::Exception’
gmm.cpp:(.text+0xbd3): undefined reference to `fl::fuzzylite::logging()’
gmm.cpp:(.text+0xbe0): undefined reference to `fl::fuzzylite::decimals()’
gmm.cpp:(.text+0xc09): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> > fl::Operation::str<double>(double, int)’
gmm.cpp:(.text+0xc11): undefined reference to `fl::fuzzylite::decimals()’
gmm.cpp:(.text+0xc2c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> > fl::Operation::str<double>(double, int)’
collect2: ld returned 1 exit status`Any help would be really appreciated.
Thanks,
Gaurav.August 20, 2014 at 08:14 #1383Juan Rada-Vilela (admin)
KeymasterHi,
The problem you are having is upon linking the library. I cannot remember what it was that I used to do to fix this type of error, but I remember a quick (and dirty) workaround was to have the library in the same folder where you are compiling. I also have the idea that it always worked when using the static library instead.
Perhaps someone else could give you a more concrete and better answer.
August 20, 2014 at 19:24 #1384Unknown
MemberHi Juan,
Thanks for the reply.
Looks like I will have to export “C” all the class definitions to work this out.Regards,
Gaurav -
AuthorPosts
- You must be logged in to reply to this topic.