首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义的建筑符号x86_64: x86_64“

未定义的建筑符号x86_64: x86_64“
EN

Stack Overflow用户
提问于 2018-09-10 05:47:39
回答 1查看 3.4K关注 0票数 4

我正在为我的数据结构类做一个项目。我从未使用过c++,而且我几乎没有学习如何将文件单独编译成.o文件,然后将这些文件链接到一起以生成可执行文件,因此,要想使这些文件不向我抛出错误是非常困难的。

我们得到了一个:

  • 头文件,stats.h
  • 一个测试程序的文件,stats.cpp
  • 一份文件,看看如果我们提交的话我们会得到多大的分数。

我们应该创建一个:

  • 实现文件,stats.cpp,它创建一个构造函数和几个函数。

这是状态。h:

代码语言:javascript
复制
// FILE: stats.h
// CLASS PROVIDED: statistician
//   (a class to keep track of statistics on a sequence of real numbers)
//   This class is part of the namespace CISP430_A1.
//
// CONSTRUCTOR for the statistician class:
//   statistician( );the
//     Postcondition: The object has been initialized, and is ready to accept
//     a sequence of numbers. Various statistics will be calculated about the
//     sequence.
//
// PUBLIC MODIFICATION member functions for the statistician class:
//   void next(double r)
//     The number r has been given to the statistician as the next number in
//     its sequence of numbers.
//   void reset( );
//     Postcondition: The statistician has been cleared, as if no numbers had
//     yet been given to it.
//   
// PUBLIC CONSTANT member functions for the statistician class:
//   int length( ) const
//     Postcondition: The return value is the length of the sequence that has
//     been given to the statistician (i.e., the number of times that the
//     next(r) function has been activated).
//   double sum( ) const
//     Postcondition: The return value is the sum of all the numbers in the
//     statistician's sequence.
//   double mean( ) const
//     Precondition: length( ) > 0
//     Postcondition: The return value is the arithmetic mean (i.e., the
//     average of all the numbers in the statistician's sequence).
//   double minimum( ) const
//     Precondition: length( ) > 0
//     Postcondition: The return value is the tiniest number in the
//     statistician's sequence.
//   double maximum( ) const
//     Precondition: length( ) > 0
//     Postcondition: The return value is the largest number in the
//     statistician's sequence.
//
// NON-MEMBER functions for the statistician class:
//   statistician operator +(const statistician& s1, const statistician& s2)
//     Postcondition: The statistician that is returned contains all the
//     numbers of the sequences of s1 and s2.
//   statistician operator *(double scale, const statistician& s)
//     Postcondition: The statistician that is returned contains the same
//     numbers that s does, but each number has been multiplied by the
//     scale number.
//   bool operator ==(const statistician& s1, const statistician& s2)
//     Postcondition: The return value is true if s1 and s2 have the zero
//     length. Also, if the length is greater than zero, then s1 and s2 must
//     have the same length, the same  mean, the same minimum, 
//     the same maximum, and the same sum.
//     
// VALUE SEMANTICS for the statistician class:
// Assignments and the copy constructor may be used with statistician objects.

#ifndef STATS_H     // Prevent duplicate definition
#define STATS_H
#include <iostream>

namespace CISP430_A1
{
    class statistician
    {
    public:
        // CONSTRUCTOR
        statistician( );
        // MODIFICATION MEMBER FUNCTIONS
        void next(double r);
        void reset( );
        // CONSTANT MEMBER FUNCTIONS
        int length( ) const { return count; }
        double sum( ) const { return total; }
        double mean( ) const;
        double minimum( ) const;
        double maximum( ) const;
        // FRIEND FUNCTIONS
        friend statistician operator +
        (const statistician& s1, const statistician& s2);
        friend statistician operator *
        (double scale, const statistician& s);
 private:
    int count;       // How many numbers in the sequence
    double total;    // The sum of all the numbers in the sequence
    double tiniest;  // The smallest number in the sequence
    double largest;  // The largest number in the sequence
};

// NON-MEMBER functions for the statistician class
bool operator ==(const statistician& s1, const statistician& s2);
}

#endif

下面是我正在处理的stats.cpp文件,到目前为止,我只创建了一个构造函数,它编译:

代码语言:javascript
复制
#include "stats.h"

namespace CISP430_A1
{
    statistician::statistician() : count(0), total(0) 
    {
    }

    }

这是stattest.cpp (我把它保存在HelloWorldII.cpp下)文件,我们给它测试它。我仅将其限制为实例化三个统计员对象并打印出一行的部分:

代码语言:javascript
复制
// FILE: stattest.cxx
// An interactive test program for the statistician class


#include <cctype>    // Provides toupper
#include <iomanip>   // Provides setw to set the width of an output
#include <iostream>  // Provides cout, cin
#include <cstdlib>   // Provides EXIT_SUCCESS
#include "stats.h"
using namespace CISP430_A1;
using namespace std;

// PROTOTYPES of functions used in this test program:
void print_menu( );
// Postcondition: A menu of choices for this program has been written to cout.
// Library facilties used: iostream.h

char get_user_command( );
// Postcondition: The user has been prompted to enter a one character command.
// A line of input (with at least one character) has been read, and the first
// character of the input line is returned.

double get_number( );
// Postcondition: The user has been prompted to enter a real number. The
// number has been read, echoed to the screen, and returned by the function.

void print_values(const statistician& s);
// Postcondition: The length, sum, minimum, mean, and maximum of s have been
// written to cout, using a field width of 10 for each of these values.
// (If length is zero, then minimum, mean, and maximum are not written.)

int main( )
{
    statistician s1, s2, s3;  // Three statisticians for us to play with
    char choice;              // A command character entered by the user
    double x;                 // Value for multiplication x*s1

    cout << "Three statisticians s1, s2, and s3 are ready to test." << endl;

}

我编译了stats.cpp和HelloWorldII.cpp,如下所示:

代码语言:javascript
复制
gcc -c stats.cpp
gcc -c HelloWorldII.cpp

然后尝试将它们编译成这样的可执行文件:

代码语言:javascript
复制
gcc -omyprogram stats.o HelloWorldII.cpp

这反过来又给了我这个错误:

我的构造函数有什么问题吗?语法错误?我的图书馆漏了什么东西吗?

另外,我可以在命令提示符中键入什么来显示我安装的OS、gcc和其他东西的版本?也许这将有助于确定问题。

EN

回答 1

Stack Overflow用户

发布于 2018-09-10 06:36:21

您需要使用g++而不是gcc来编译和链接c++代码。

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52251766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档