Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Gateway + to compile CPP files in Ubuntu environment

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use CPP + to compile CPP files in the Ubuntu environment, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The error of undefined reference was reported when compiling the cpp file with Gmail + for the first time. All the functions in the custom class could not be found. After looking up the data, we found that the called class needed to be linked. This paper uses a small example to describe the compilation process. The class2 class calls the member function of the class1 class, which depends on the class1 class, while the test file calls the member function of the class2 class, which depends on the class1 class.

/ / class1.h#ifndef _ CLASS1_H#define _ CLASS1_Hclass class1 {public: int f (int I);}; # endif//class1.cpp#include#include "class1.h" using namespace std;int class1::f (int I) {if (iMoh1) return 1; else return f (iMuth1) + f (iMuth1);} / / class2.h#ifndef _ CLASS2_H#define _ CLASS2_H#include "class1.h" class class2 {public: int double_f (int I);} # endif//class2.cpp#include#include "class2.h" using namespace std;int class2::double_f (int I) {class1 c; return 2*c.f (I);} / / test.cpp#include#include "class2.h" using namespace std;int main () {class2 c2; cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report