nmake编译dll

来源:互联网 发布:淘宝上刘雨晴 编辑:程序博客网 时间:2024/06/05 19:02

想弄nmake,百度上基础资料太少,都是linux的makefile,弄了2天才一点点效果

头痛中。。。


以下记录

//main.cpp

#include <iostream>
using namespace std;

//把Test.h改名为TestLib.h,并去掉_declspec(dllexport) 
#include "TestLib.h"
#pragma comment(lib, "Test.lib")
int main()
{
cout<<"hello world"<<endl;

string curName;
Test t;
t.printName("wujingtao", curName);
int num = t.getNum();
string cnName = t.getCnName();
string usName = t.getUsName();

cout<<curName<<endl;
cout<<usName<<endl;
cout<<cnName<<endl;
cout<<num<<endl;

system("pause");
return 0;
};

//Test.h

#ifndef Test_H
#define Test_H

#include <string>         
using std::string;        

class _declspec(dllexport) Test
{
public:
string printName(const string& usName, string& cnName);

int getNum();

string getUsName();

string getCnName();
};
#endif


//Test.cpp
#include "Test.h"
string Test::printName(const string& usName, string& cnName)
{
string tmpName="";
if("wujingtao"== usName)
{
    tmpName = "吴竞焘";
}
cnName = tmpName;
    
return tmpName;
}


int Test::getNum()
{
return 5;
}

string Test::getCnName()
{
return "吴竞焘";
}

string Test::getUsName()
{
return "wujingtao";
}

//makefile

all:main.obj Test.lib

link main.obj Test.lib 
main.obj:
cl /c /EHsc main.cpp
Test.lib:Test.obj
link /Dll Test.obj
Test.obj:Test.h
cl /c /EHsc Test.cpp

clean:
@del *.obj
@echo Project has clean
0 0
原创粉丝点击