忍者ブログ
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2024年04月29日13:11 】 |
DLLの作成方法③ Linux編 
以前作ったサンプル。

$ make 
g++ -fPIC mydll.cpp -c -o mydll.o 
g++ -shared -o libmydll.so.3 mydll.o 
g++ -o main main.cpp ./libmydll.so.3 
$ ./main 
test ok. 
get 
test::get 
put 
test::put 
ee 

---make--------------------------------
 
comp:
g++ -fPIC mydll.cpp -c -o mydll.o
g++ -shared -o libmydll.so.3 mydll.o
g++ -o main main.cpp ./libmydll.so.3
# or
# libmydll.so.3 -> lib***.so**
# g++ -o main main.cpp -lmydll
# when /usr/lib/libmydll.so.3 
#
 
compc:
g++ -fPIC mydll.cpp -c -o mydll.o
g++ -shared -o libmydll.so.3 mydll.o
gcc -o mainc mainc.c ./libmydll.so.3
# or
# libmydll.so.3 -> lib***.so**
# g++ -o main main.cpp -lmydll
# when /usr/lib/libmydll.so.3 
#
 
clean:
rm -f *.so.* main *.o
 


---main.cpp--------------------------------
#include <stdio.h>
 
extern "C" {
 //typedef struct _MEMBER{
  extern void testfunc();
  extern void get(char* str);
  extern char *put();
 //}MEMBER;
}
 
//MEMBER mem;
 
int main() {
  testfunc();
  get("ee");
  
  printf("%s\n", put());
  
  return 0;
}
 


---mydll.cpp--------------------------------

#include <stdio.h>
#include <string.h>
 
extern "C" {
void testfunc();
void get(char* str);
char *put();
}
 
 
 
class test{
private:
char buf[1024];
public:
test(){
 //buf=0;
}
~test(){}
void get(char* str);
char* put();
};
 
void test::get(char* str){
  printf("test::get\n");
strcpy(buf,str);
}
 
char* test::put(){
  printf("test::put\n");
return buf;
}
 
 
test tes;
 
void testfunc() {
  printf("test ok.\n");
}
 
void get(char* str) {
  printf("get\n");
  tes.get(str);
}
 
 
char* put() {
  printf("put\n");
  return tes.put();
}
 
 
 
 
 

PR
【2012年04月30日08:55 】 | 未選択 | コメント(0)
コメントの投稿













前ページ | ホーム | 次ページ

忍者ブログ [PR]