c++ - 链接头文件c ++时对函数的未定义引用
问题描述
我正在尝试在 Bjarne stroustrup 的书中进行第 8 章的练习。我已按照所有步骤操作,但在运行程序时出现两个错误:未定义对“print_foo”的引用未定义对“print(int)”的引用。我使用 VSC。
这是我的文件:
------我的.h-----
extern int foo;
void print_foo();
void print(int);
--------my.cpp--------
#include"std_lib_facilities.h"
#include"my.h"
void print_foo()
{
cout<<"foo = "<<foo<<'\n';
}
void print(int i)
{
cout<<"i = "<<i<<'\n';
}
--------使用.cpp--------
#include<iostream>
#include"my.h"
using namespace std;
inline void keep_window_open() {char cc;cin>>cc;}
int main()
{
int foo = 7;
print_foo();
print(99);
return 0;
}
解决方案
推荐阅读
- java - 我在 Java 中做错了什么?
- c++ - 如果在 constexpr 上下文中,如何在 assert() 和 static_assert() 之间分派,依赖?
- android - 我们如何在三星平板电脑中设置信息亭模式?
- javascript - 使用 JavaScript 中的正则表达式在 jstree 中选择一个节点
- java - 在微服务应用程序中打包公共代码
- rtf - 在 BI Publisher rtf 模板的 for-each 循环中使用分节符
- r - R. 选择观察开始于
- java - @Select 在没有参数而不是选择所有实体时引发错误(Datastax Java Driver Mapper)
- sql-server - 在 SSIS 中使用动态变量连接到 SQL Server
- c++ - 如何将独立的 c 应用程序组合成 c++ 应用程序?