Reputation: 2682
I want to use a source file, say foo.cpp
with other c++ projects. One way to do this is having a header file and providing the source file as command line arguments to g++. But I want to compile it once, store it somewhere, and use it simply by including the header file, just like we do with iostream
where we don't include it as a build argument to g++.
I assume even if we build it as a custom library, still we need to provide the .object
or equivalent file as an argument to g++ right? Whereas for iostream
, its implementation is compiled and linked with our cpp file, although we don't mention it explicitly like g++ foo.cpp iostream
.
For instance, consider this:
foo.h
#ifndef FOO_H
#define FOO_H
void disp();
#end
foo.cpp
#include<weiostream>
void disp()
{
std::cout<<"Hello World";
}
main.cpp
#include<iostream>
#include "foo.h" \* I just wnat this to be like iostream and not
providing it as command-line argument *\
int main()
{
disp();
return 0;
}
It may be pointless to do it for this small program, but I am curious regarding the larger concept! And I am curious if iostream
header file simply contains definitions or some mechanism to call its implementation library g++?
Upvotes: 0
Views: 78