Sublime Forum

C++ Not compiling multi-file programs

#1

I am to compile a multi-file C++ program, and have the following error;

Undefined symbols for architecture i386: "included::printMSG()", referenced from: _main in ccQwMj1l.o ld: symbol(s) not[Finished in 0.3s with exit code 1] found for architecture i386 collect2: ld returned 1 exit status

My code:
main.cpp: gist.github.com/3845822
included.cpp: gist.github.com/3845825
included.h: gist.github.com/3845827
(confirmed to work with g++)

EDIT: I am not putting these files in a project, they are just all in the same folder, and I’m compiling main.cpp

0 Likes

#2

Don’t know if you figured this out yet, or if you still care, but here are some things that might help.

First, assuming you haven’t created any special builds, which I don’t think you did, it is probably using the default C++ build, which can be found in Packages/C++/C++.sublime-build. It looks like it only compiles a single file. Second, have you tried looking at the console output? It displays the command being run and can be accessed via “View -> Console” or the shortcut key “Ctrl/Cmd + `” by default.

Hope that helps.

0 Likes

#3

Did you find a solution for this issue, I have the same. I think I know the cause, but since I’m not a familiar with developing on OS X nor Sublime Text 2 user I dont know how to fix it. I think it doesnt compile the .cpp files but only the header-files thus the implementations are undefined and the compilation fails.

writing this in terminal:
i.e g++ main.cpp test.h -o testbuild fails with same kind of error
g++ main.cpp test.cpp -o testbuild succeeds

I am using a freshly reinstalled macbook pro 10.7.5, new installed xcode with commandline toolset and fresh install of sublime no custom builds added. I really want a solution to this, any help is appreciated!

EDIT:
I just realised that I am stupid, and the issue is resolved by using a Makefile -_-

0 Likes