GodOnScooter
GodOnScooter

Reputation: 33

Linking c++ files

I have A header file which contains declaration of a function, let's call it A.h, i have implementation of this function in file A1.cpp. Now A1.cpp has other file includes. Not all included files in A1.cpp are available (3rd party issue). Now my question is , Is it possible to make function call from a file let's say main.cpp, dynamically linking to A1.cpp(without compiling A1.cpp) as i have some files from 3rd party not available ?

My guess is no, because unless i have included files available i can't get object file of A1.cpp and hence i can't call function. However correct me if i am wrong , a compiled file of A1.cpp i.e A1.o can still be used as i can link to it and hence make function call without dependency on other include files(which i don't have?)

Go easy on me , i'm not a C++ guy :-) !! Any help or insight in this matter is appreciated !! Oh btw i have started to use ndk for android, n hence the trouble :-)

Upvotes: 0

Views: 362

Answers (2)

nc3b
nc3b

Reputation: 16220

If you have the object file (A.o) why can't you just link it in your binary ?

g++ -o main main.o A.o

Upvotes: 1

Luther
Luther

Reputation: 1838

If I've understood your question right then the answer is no, not when the target is just a cpp file. The only ways to link to something else without compiling it would be to put it in a dll or a precompiled library (.lib in windows). If the third part stuff is in a .lib or a dll then you should be in luck, you just need the header file and then tell your compiler to link the static or dynamic library. Let me know if that made sense, if not I can clarify given more information about your set up and what you're trying to link.

Upvotes: 0

Related Questions