1

I've created a .so file called car.so. I would like to test and work with this library in a test.cc code . In the command line i would like to compile: g++ test.cc -o test. I don't want to also link (include) the library car.so.

How to do that?

My test.cc code looks like this:

void* handle = dlopen("/home/v3/car.so", RTLD_LAZY); Car* (*create)(); void (*destroy)(Car*); create = (Car* (*)())dlsym(handle, "create_object"); destroy = (void (*)(Car*))dlsym(handle, "destroy_object"); Car* carr = (Car*)create(); carr->brake(); destroy( carr ); 

I would also like to ask if it's possible to include 3 .so file in a single .so file.

edit:

I am working on Ubuntu/Linux

5
  • Have a look at dynamic linking. This is operating-system dependent, but I assume you use some kind of Linux. There, have a look at dlsym and related functions. Commented Sep 5, 2011 at 7:59
  • YES. I AM WORKING OB UUNTU. WHAT DO YOU MEAN BY OPERATING SYSTEM DEPENDENT? IS IT POSSIBLE OR NOT TO RUN WITH G++ A C FILE THAT CONTAINS A LIBRARY WITHOUT INCLUDING THE LIBRARY TO THE COMPILATION COMMAND? Commented Sep 5, 2011 at 8:07
  • 6
    Man, it's something wrong with your Caps Lock Commented Sep 5, 2011 at 8:10
  • Yes it is possible. Within your source code, you load the library and use dlsym etc to find symbols in it. I don't know the syntax by heart, but the man pages for dlsym and related functions should help you out. Commented Sep 5, 2011 at 8:29
  • 1
    Creating a new question for you additional question is the best way to get good answers to it, as it is completely separate question (at least for us) Commented Sep 5, 2011 at 8:37

1 Answer 1

2

in General you should include .h file of your .so library in your (application)/ test.cc then compile that test.cc file by linking that .so file & use generated binaray.

i think this link will realy help you.. http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

Sign up to request clarification or add additional context in comments.

2 Comments

if i use dlsym is it necesarry and use -ldl is it necesarry to link with -llibrary?
ya it is necessory because when your execuatable is going to run it should be know where .so will be..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.