• pytorch源码解析-动态接口宏


    动态库接口定义:
    	gcc:
    		定义在动态库的显示属性:
    			作用对象: 	函数、变量、模板以及C++类
    			default:	表示在动态库内可见
    			hidden:		表示不可见
    		#define EXPORT __attribute__((__visibility__("default")))
    	微软:
    		#define C10_EXPORT __declspec(dllexport)	 制作dll时候用
    		#define C10_IMPORT __declspec(dllimport)	 调用dll时候用
    			放到同一个api 头文件中	
    			当编译的时候用export
    			调用的时候用 import 
    
    	通常用法:
    		class API Tensor {};
    
    	常用方法:
    	#ifdef _WIN32
    		#windows编译
    		#if defined(C10_BUILD_SHARED_LIBS)		#如果定义动态库
    			#define C10_EXPORT __declspec(dllexport)
    			#define C10_IMPORT __declspec(dllimport)
    		#else
    			#define C10_EXPORT
    			#define C10_IMPORT
    		#endif
    	#else // _WIN32
    		#if defined(__GNUC__)
    			#define C10_EXPORT __attribute__((__visibility__("default")))
    		#else // defined(__GNUC__)
    			#define C10_EXPORT
    			#endif // defined(__GNUC__)
    		#define C10_IMPORT C10_EXPORT
    	#endif // _WIN32
    
    
    	#ifdef BUILD_MAIN_LIB			#编译的时候 这个有定义   调用的时候没有定义
    		#define API C10_EXPORT
    	#else
    		#define API C10_IMPORT
    	#endif
    
    	真正使用的时候使用: API 便可
    
  • 相关阅读:
    完美世界笔试(动态规划,背包问题)
    腾讯笔试3
    腾讯笔试2
    腾讯笔试1
    阿里笔试1
    Merge Sorted Array
    Partition List
    Reverse Linked List II
    Remove Duplicates from Sorted List II
    白菜刷LeetCode记-704. Binary Search
  • 原文地址:https://www.cnblogs.com/longriyao/p/10802682.html
Copyright © 2020-2023  润新知