首页 > 其他分享 >undefined reference to `add(int, int)'

undefined reference to `add(int, int)'

时间:2023-11-08 11:22:54浏览次数:27  
标签:文件 undefined reference int add cpp

一、概述

  使用cmake编译C++项目报

 undefined reference to `add(int, int)'

  项目中有.cpp文件,有.h文件,有.c文件。也就是c和c++混编。其中.cpp文件引用了.c的头文件

  现象:

   从上面可以看出其实这几个.cpp和.c文件都已经编译过了。但是就会提示找不到.c文件中的方法

二、解决办法

  原因在于.c和.cpp文件混编的时候需要在.h文件中加入一个判断,如果是c++环境则需要加上extern "C"。如下:

#ifndef _HEAD_H
#define _HEAD_H

#ifdef __cplusplus
extern "C"{
#endif

//加法
int add(int a,int b);
//减法
int subtract(int a,int b);
//乘法
int multiply(int a,int b);
//除法
double divide(int a,int b);

#ifdef __cplusplus
}
#endif

#endif

 

  

标签:文件,undefined,reference,int,add,cpp
From: https://www.cnblogs.com/tony-yang-flutter/p/17816970.html

相关文章

  • .net core webapi Startup services.AddHttpClient
    staticpublicclassCreditScoreServiceExtension{staticpublicvoidAddCreditScoreQueryServiceHttpClient(thisIServiceCollectionservices,IConfigurationconfig){services.AddSingleton<ICreditScoreQueryService,CreditS......
  • How to add an image on reportViewer (rdlc)
    OpenthereportintheDesigner.IntheToolBox,select/expandthe"ReportItems"section.Dragan"Image"field/controlontothereport.ClickontheimageandpressF4,thepropertieswindow popsup,underthegroupdatayou'llf......
  • C# 一款免费且离线的.NET使用的OCR,PaddleOCRSharp
    本项目是一个基于百度飞桨[PaddleOCR](https://github.com/paddlepaddle/PaddleOCR)的C++代码修改并封装的.NET的工具类库。包含文本识别、文本检测、基于文本检测结果的统计分析的表格识别功能,同时针对小图识别不准的情况下,做了优化,提高识别准确率。包含总模型仅8.6M的超轻量级中......
  • linux print_hex_dump()
    linuxprint_hex_dump()linux/lib/hexdump.c/***print_hex_dump-printatexthexdumptosyslogforabinaryblobofdata*@level:kernelloglevel(e.g.KERN_DEBUG)*@prefix_str:stringtoprefixeachlinewith;*callersuppliestrailingspac......
  • 论文阅读:Point-BERT: Pre-training 3D Point Cloud Transformers with Masked Point M
    Point-BERT:Pre-training3DPointCloudTransformerswith MaskedPointModelingPoint-BERT:基于掩码建模的点云自注意力模型预训练摘要我们提出了Point-BERT,一个学习自注意力的新范式,将BERT[8]的概念推广到三维点云。受BERT的启发,我们设计了一个掩蔽点建模(MPM)任务来预训练点云......
  • 论文阅读:Local and Global Structure for Urban ALS Point Cloud Semantic Segmentati
    LocalandGlobalStructureforUrbanALSPoint CloudSemanticSegmentationWith Ground-AwareAttention利用地面感知注意力对城市ALS点云进行局部和全局结构的语义分割摘要机载激光扫描(ALS)点云的解释在地理信息生产中起着显著的作用。作为解释的关键步骤,准确的语义分割可以......
  • .netCoreApi5.0+部署iis站点webconfig配置 HTTP 错误 500.24 - Internal Server Error
     <?xmlversion="1.0"encoding="utf-8"?><configuration><locationpath="."inheritInChildApplications="false"><system.webServer><handlers><addname="aspN......
  • C# 关于导出的Excel设置批注 设置格式为int类型 设置字体
    将数据导出,导出Excel有时候需要一些条件,比如:1.需要给某一列的表头加批注;2:需要设置某一列为int格式1.给某一列的表头加批注1List<string>texts=newList<string>();2List<int>ids=newList<int>();3texts.Add("......
  • BindException、ConstraintViolationException、MethodArgumentNotValidException入参
    Springvalidation验证框架注解Springvalidation验证框架提供了大量接口入参检验注解,注意三个非空注解:@NotNull:验证对象是否不为null,无法查检长度为0的字符串@NotBlank:检查约束(字符串)是不是Null还有被Trim的长度是否大于0,只对字符串,且会去掉前后空格@NotEmpty:检查(集合)......
  • Python ImportError: No module named Tkinter
    fromTkinterimport*root=Tk()root.mainloop() 运行出现错误:>>>Traceback(mostrecentcalllast):File"E:/××××/Python/test",line1,in<module>fromTkinterimport*ImportError:NomodulenamedTkinter改......