我曾经用来Xcode
构建和运行C++
程序。
我使用命令行在我的Xcode
项目中编译相同的源代码。
编译单个.cpp
文件是可以的。
编译更复杂的项目(多个文件)是不行的。
我试过了gcc
,,,,。g++
clang
clang++
主要问题是未定义的符号。
你能展示如何通过命令行编译复杂的项目(多个文件)吗?
From your description, it sounds like you're not using the -c
(compile, but don't link) flag. Steps to build your project:
Compile all of the source files:
c++ -c file1.cpp
c++ -c file2.cpp
c++ -c file3.cpp
Link your final executable:
c++ file1.o file2.o file3.o
You can use an optional -o
flag to specify the output program name. It probably defaults to a.out
.
It would be better to use some kind of build tool (like make
, for example) to automate this process, or you'll find it to be very error prone.