so动态库只导出指定函数

retain_sym.txt

1
2
func1
func2

ver_script.txt

1
2
3
4
5
6
7
LIBA_1.1 {
	global:
		foo1;
		foo2;
	local:
		*;
};
1
ld -shared --retain-symbols-file=retain_sym.txt --version-script=ver_script.txt tst.o -o tst.so

refer to:
https://blog.csdn.net/chdhust/article/details/79356717
http://blog.sina.com.cn/s/blog_493667730100csde.html
http://www.gnu.org/software/gnulib/manual/html_node/LD-Version-Scripts.html

error C2504: '_IMsoDispObj' : base class undefined

原因是mso.dll库中的定义没导入,对于装的是Office 2013的环境,正确写法是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#import "C:\\Program Files (x86)\\Common Files\\microsoft shared\\OFFICE15\\MSO.DLL" rename("RGB", "MSRGB")
 
using namespace Office;
 
#import "C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB" raw_interfaces_only, \
rename("Reference", "ignorethis"), rename("VBE", "JOEVBE")
 
using namespace VBIDE;
 
#import "C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE" exclude("IFont", "IPicture") \
rename("RGB", "ignorethis"), rename("DialogBox", "ignorethis"), rename("VBE", "JOEVBE"), \
rename("ReplaceText", "JOEReplaceText"), rename("CopyFile","JOECopyFile"), \
rename("FindText", "JOEFindText"), rename("NoPrompt", "JOENoPrompt")
 
using namespace Excel;
 
#include "CApplication.h"
#include "CWorkbooks.h"
#include "CWorkbook.h"
#include "CWorksheets.h"
#include "CWorksheet.h"
#include "CRange.h"
#include "CFont0.h"
 
//下面再写导出Excel文件的逻辑。

同时还要把这包含的Type Lib几个头文件的开头的import语句都删掉。
还要把CRange.h里的DialogBox函数注释掉。
就可以了。

还有,导出Excel文件用这种COM进程间通讯的方式最大缺点是慢,当导出条数很大时尤为明显,最好的方法是写一个C#子程序调npoi库。现在都是win7以上了,做成安装包时不需要要用户先安装.net framework之类的库。

refer to: http://blog.sina.com.cn/s/blog_7c5bff15010117cb.html