Help for beginners (C + C++)
Dobrej den programovyy!Tak sem vam tu vytvoril pomocne forum pro me :)Chtel sem si pri svych programatorskych zacatcich byt jisty ze se neucim nejake spatne navyky a ze vsemu 100% rozumim a vtom mi nejvice muzou pomoct jedine "pokrocily"!Takze tady obcas napisu nejake veci ktere me matou,ktere nechapu...predem bych chtel podekovat vsem kteri se budou mym problemem zabyvat a pomohou mi ho srovnat v hlave!! andering
Re: Help for beginners (C + C++)
Kód:
dlsym functions as described in the dlopen(3) man page
http://www.codecomments.com/archive2...12-730644.html
Kód:
Don't use dlsym. Look at somthing like Austria C++ generic factories.
It is a standard C++ way of doing the same thing. No need to use extern
"C".
Řešení nahrání externí metody
Kód:
main.cpp:
#include <iostream>
#include <dlfcn.h>
int main() {
using std::cout;
using std::cerr;
cout << "C++ dlopen demo\n\n";
// open the library
cout << "Opening hello.so...\n";
void* handle = dlopen("./hello.so", RTLD_LAZY);
if (!handle) {
cerr << "Cannot open library: " << dlerror() << '\n';
return 1;
}
// load the symbol
cout << "Loading symbol hello...\n";
typedef void (*hello_t)();
// reset errors
dlerror();
hello_t hello = (hello_t) dlsym(handle, "hello");
const char *dlsym_error = dlerror();
if (dlsym_error) {
cerr << "Cannot load symbol 'hello': " << dlsym_error <<
'\n';
dlclose(handle);
return 1;
}
// use it to do the calculation
cout << "Calling hello...\n";
hello();
// close the library
cout << "Closing library...\n";
dlclose(handle);
}hello.cpp:
#include <iostream>
extern "C" void hello() {
std::cout << "hello" << '\n';
}
opsano z http://www.isotton.com/howtos/C++-dl....html#mangling
Re: Help for beginners (C + C++)
To je rozdiel medzi C a C++. V C mozes void pointer priradit do lubovolneho ineho pointera a pretypuje sa sam. V C++ to musis rucne pretypovat.