如何让我的C++程序在 Unix 上编译
How can I get my C++ program to compile on Unix?
我正在C++从事一个学校项目,并按照教授的指示使用我们学校的Unix服务器编写它。我正在使用 vim 和 g++ 进行编译。
这个项目是在另一个项目Lab0的基础上构建的,在TA的帮助下,我毫不费力地构建了它,但不得不做一些奇怪的事情来构建它(#include LinkedSortedList.cpp文件在LinkedSortedList.h的底部(。班上的每个人都用 #include .cpp 文件做了这种奇怪的事情。
首先,以下是文件以及它们对编译良好的 Lab0 #includes:
(该帖子没有在我的制作文件中显示我的选项卡,但它们就在那里!
制作文件:
main: *.cpp *.h
g++ -o LSL main.cpp
clean:
rm -f *.o LSL*
Lab0(构建的那个(是这样的:
文件:
主.cpp(非模板化(:
#include "LinkedSortedList.h"
#include <iostream>
using namespace std;
SortedList.h (Templated(: 无
LinkedNode.h (Templated(:
#include <iostream>
using namespace std;
LinkedSortedList.h (Templated(:
#include "SortedList.h"
#include "LinkedNode.h"
#include <iostream>
using namespace std;
#include "LinkedSortedList.cpp" // At the bottom fo this file above the #endif to get the program to compile from what the TA told me to do for lab0 due to the templated class.
LinkedSortedList.cpp (Templated(: 无
构建和运行此项目没有问题。
这是我的问题:
下面是 lab1,我遇到问题的那个,Lab1 使用 Lab0 中的所有文件,只是添加了 Employee.h 和 Employee.cpp。
Lab1(不会构建的那个(是这样的:
文件:
实验1.cpp:
#include <iomanip>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include "Employee.h"
#include "LinkedSortedList.h"
SortedList.h (Templated(: 无
LinkedNode.h (Templated(:
#include <iostream>
using namespace std;
LinkedSortedList.h (Templated(:
#include "SortedList.h"
#include "LinkedNode.h"
#include "Employee.h"
#include <iostream>
using namespace std;
#include "LinkedSortedList.cpp" // At the bottom fo this file above the #endif to get the program to compile from what the TA told me to do for lab0 due to the templated class.
LinkedSortedList.cpp (Templated(: 无
员工.h (非模板化(:
#include <iostream>
#include <sstream>
using namespace std;
员工.cpp(非模板(:
#include <stdio.h>
#include <string.h>
(该帖子没有在我的制作文件中显示我的选项卡,但它们就在那里!
makefile:
main: *.cpp *.h
g++ -o LSL lab1.cpp
clean:
rm -f *.o LSL*
我得到的错误:
这是我遇到的错误。似乎看不到 Employee.cpp/Employee.h 文件。任何想法??
Unixserver:Lab1> makeg++ -o LSL lab1.cpp/tmp/ccamnaqx.o: 在函数中
createRecord()':
lab1.cpp:(.text+0x3fb): undefined reference to
Employee::Employee(('lab1.cpp:(.text+0x477(: 未定义对Employee::setLastName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x4f2): undefined reference to
Employee::setFirstName(std::basic_string, std::分配器>('lab1.cpp:(.text+0x589(:未定义对Employee::setId(int)'
lab1.cpp:(.text+0x5ce): undefined reference to
Employee::setSalary(int('lab1.cpp:(.text+0x60e(:未定义对Employee::setDepartment(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x67c): undefined reference to
Employee::setPhoneNumber(std::basic_string, std::分配器>('lab1.cpp:(.text+0x6ea(: 未定义对Employee::setAddress(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
lab1.cpp:(.text+0x758): undefined reference to
Employee::setHireDate(std::basic_string, std::分配器>('lab1.cpp:(.text+0x7c6(:未定义对"Employee::setEmailAddress(std::basic_string, std:::allocator>("的引用收集2:LD 返回 1 个退出状态制造: * [主要] 错误 1
任何帮助将不胜感激!
您必须编译Employee.cpp
并将其链接到可执行文件中:
g++ -o LSL lab1.cpp Employee.cpp
LinkedSortedList.cpp
可能也是如此(我并不完全清楚它的目的(。
第二个项目的生成文件仅编译 lab1.cpp而不编译其他 cpp 文件。 您还有另外两个(Employee.cpp和LinkSortedList.cpp(需要考虑。
另外,请在此站点上了解如何正确格式化代码。 https://stackoverflow.com/editing-help
- 二叉排序树无法编译
- 编译时未启用intel oneApi CUDA支持
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- Unix 宏在使用 -std=c++0x 标志编译时变得未定义
- 双击编译C++ Unix 可执行文件不会打开现有文件以从中读取信息
- 在 Unix 中编译 c++ 时嵌套模板参数出错
- 如何在Windows中为Unix/Linux编译C++应用程序
- Unix可执行文件上的Mac分段错误,文件编译正常
- Unix 命令行在编译后无法运行程序,没有错误消息
- 为什么这会在Visual Studio 2012中编译,而不是UNIX
- 为什么这不能在我的学校 unix 系统上编译?
- 如何让我的C++程序在 Unix 上编译
- 在unix中编译dhrystone时出错
- 在Unix/Linux(Ubuntu)中编译头文件和两个.cpp文件
- 在Unix上编译所有的boost库
- 我得到编译器错误,而在unix中编译我的代码
- 如何查找UNIX的编译时间
- 从Visual Studio 2012为Windows和UNIX计算机编译项目
- 代码在Visual Studio中可以很好地编译,但在使用g++的Unix终端中就不行了.我在多维向量处得到一个错误.为
- AIX unix服务器上的c++编译错误