Home Download Buy Blog Forum Support

C++ Not compiling multi-file programs

C++ Not compiling multi-file programs

Postby jackwilsdon on Sat Oct 06, 2012 7:45 pm

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

Code: Select all
    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: https://gist.github.com/3845822
included.cpp: https://gist.github.com/3845825
included.h: https://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`
Posts: 1
Joined: Sat Oct 06, 2012 7:43 pm

Re: C++ Not compiling multi-file programs

Postby skuroda on Mon Oct 08, 2012 6:33 am

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.
Posts: 692
Joined: Fri Oct 05, 2012 8:11 am

Re: C++ Not compiling multi-file programs

Postby zerorepent on Tue Dec 11, 2012 2:01 pm

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!

I just realised that I am stupid, and the issue is resolved by using a Makefile -_-
Posts: 1
Joined: Tue Dec 11, 2012 1:43 pm

Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot] and 18 guests