The .cpp files are never included by other files (well you could, but by good organization practices they don't). They are the 'starting points' of compilation units, which go on to include headers. Each .cpp file is compiled separately as their own compilation unit, and the results are linked together. You must have somehow confused the examples you looked at - all C++ compilers do this: you pass all the .cpp files to the compiler either via a single "cc a.cpp b.cpp c.cpp -o a.out" directive, or via separate directives that create object files "cc a.cpp -o a.obj;cc b.cpp -o b.obj;cc c.cpp -o c.obj" and then finally combine them together with "cc a.obj b.obj c.obj -o a.out". Visual Studio traditionally uses the suffix .obj for intermediate object files, GCC uses .o, emcc can use either. It is also possible to make more complex build hierarchies by compiling multiple object files to static libraries, and then finally combine the individual static libraries to produce the final executable. Perhaps the examples you were looking at all built individual object files, and therefore only ever called emcc with a single .cpp file at a time?
2014-02-11 20:55 GMT+02:00 Jack Arrington <[email protected]>: > First I should say that I am far from a C++ ninja, and I've only compiled > a few simple things with emscripten thus far. > > So I have my main.cpp file, and a class called Foo in Foo.h and Foo.cpp. > main.cpp includes Foo.h and Foo.cpp includes Foo.h, but when I compile, I > get the error: "warning: unresolved symbol: _ZN5FooC1EV". My understanding > was that this was the standard way of doing things in C++. *However, *when > I switch the contents of Foo.h and Foo.cpp to a function declaration and > implementation, respectively, I get no such error. When I change the > contents of my Makefile from "emcc -g4 src/main.cpp -o out/main.js" to > "emcc -g4 src/main.cpp src/Foo.cpp -o out/main.js", everything works. This > makes sense to me, since Foo.cpp is not actually getting *included *anywhere > in the code. But what confuses me is that all the emscripten examples I > have read do not seem to do this, and code like this works with > cl(Microsoft's C++ compiler). > > Did I miss something here? Am I making a dumb mistake? Any help is > appreciated.(below is posted my code) > > Main.cpp: > #include <iostream> > #include <stdio.h> > #include "Foo.h" > > int main(int argc, char const *argv[]) > { > Foo f; > printf("%i\n", f.bar); > > return 0; > } > > Foo.h: > #ifndef FOOH > #define FOOH > #pragma once > > class Foo > { > public: > Foo(); > ~Foo(); > > int bar; > }; > > #endif > > Foo.cpp: > #include "Foo.h" > > Foo::Foo() > { > printf("Hello\n"); > bar = 12; > } > > Foo::~Foo() > { > > } > > Makefile: > emcc -g4 src/main.cpp src/Foo.cpp -o out/main.js > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
