从命令行定义源文件的宏
Defining macros for a source file form the command line
>我正在尝试使用 -D 标志从 ubuntu 系统上的命令行为源文件定义宏。源文件为:
#include<iostream>
using namespace std;
int factorial(int n){
if(n!=1){
return(n * factorial(n-1));
}
else return 1;
#ifdef DEEPAK
cout<<"hello"<<endl;
#endif
}
int main()
{
factorial(4);
return(0);
}
我正在键入的命令是:
gcc -Wall -DDEEPAK factorial.cpp -o main
但是,我收到错误:
/tmp/cc4Ii5l2.o: In function `__static_initialization_and_destruction_0(int, int)':
factorial.cpp:(.text+0x63): undefined reference to `std::ios_base::Init::Init()'
factorial.cpp:(.text+0x72): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
任何帮助将不胜感激。谢谢。
您应该
在命令中使用g++
而不是gcc
,因为默认情况下gcc
不会链接到C++ STL,因此它给出了对std::ios_base
的未定义引用。
g++ -Wall -DDEEPAK factorial.cpp -o main
相关文章:
- 使用多个源文件时对类成员函数的未定义引用
- C++,是否有可能/如何定义在.h和.cpp源文件中调用函数的类构造函数
- C++ 在一个源文件中使用另一个源文件中的矢量定义
- C++:实现定义了可接受的物理源文件字符
- 有没有办法声明一个公共静态常量,该常量将使用 constexpr 在源文件中定义(有什么区别)?
- 如何在源文件中定义模板函数
- 避免对仅在源文件中定义的类发出弱 vtable 警告
- 从源文件中定义的类访问标头中定义的类的私有变量
- 使用TSHARK C 源文件时未定义的参考在添加所需库后剖析消息
- 在源文件中定义链接选项C++
- 如何将包含多个.cpp源文件的文件夹导入Eclipse项目中,每个源文件都有一个main()定义
- 我应该在源文件之间共享的常量的定义中添加关键字"extern"吗
- 在源文件中定义 const 数组
- 从C源文件调用C++源文件中定义的全局函数
- 源文件中定义静态原子变量不好
- 如何在源文件中定义类并将其声明在标题文件中(而不必使用`class :: method'语法定义类方法)
- 在源文件中定义数组,然后在其他源文件中使用它
- 在C中如何在命令行中定义所有不知道宏(在源文件/标头文件中使用)
- 如何从另一个.cpp源文件调用main.cpp中定义的方法
- C++ - 定义类模板(头文件/源文件)