dll调用lib的出错的有关问题
dll调用lib的出错的问题
首先建立了一个lib工程:add
//add.h
#ifndef LIB_H
#define LIB_H
extern "C " int add(int x,int y); //declare c compile external function
#endif
//add.cpp
#include "add.h "
int add(int x,int y){
return x + y;
}
再建立一个非MFC的dll工程:addcalldll
//libcall.h
#ifndef LIB_H
#define LIB_H
extern "C " int _declspec(dllexport) add1(int x, int y);
#endif
//libcall.c
#include "libcall.h "
#include "..\\add\\add.h "
#pragma comment(lib, "..\\add\\debug\\add.lib ") //define static library
extern "C " _declspec(dllimport) int add(int x,int y);
int add1(int x, int y)
{
return add(x,y);
}
可是在build的时候出错:
Compiling...
libcall.c
c:\testlib\addcalldall\libcall.h(5) : error C2059: syntax error : 'string '
c:\testlib\addcalldall\libcall.c(4) : error C2059: syntax error : 'string '
如果建立一个exe工程调用lib的时候不会出错,难道dll中调用lib要使用什么特殊的处理吗?
//exe工程调用方式:
//main.cpp
#include <stdio.h>
#include "..\\add\\add.h "
#pragma comment(lib, "..\\add\\debug\\add.lib ") //define static library
int main(int argc,char* argv[])
{
printf( "2+3 = %d ",add(2,3));
return 0;
}
我看 < < VC++动态链接库(DLL)编程深入浅出(一)> >
静态链接库和动态链接库的另外一个区别在于静态链接库中不能再包含其他的动态链接库或者静态库,而在动态链接库中还可以再包含其他的动态或静态链接库。
不知那位大人能帮我看看?
------解决方案--------------------
首先纠正一下:静态链接库和动态链接库的另外一个区别在于静态链接库中不能再包含其他的动态链接库或者静态库,这句话是错的,静态库中可以再包含其他的库.
------解决方案--------------------
//libcall.c
#include "libcall.h "
#include "..\\add\\add.h "
#pragma comment(lib, "..\\add\\debug\\add.lib ") //define static library
--> > 把这个注释掉试试//extern "C " _declspec(dllimport) int add(int x,int y);
首先建立了一个lib工程:add
//add.h
#ifndef LIB_H
#define LIB_H
extern "C " int add(int x,int y); //declare c compile external function
#endif
//add.cpp
#include "add.h "
int add(int x,int y){
return x + y;
}
再建立一个非MFC的dll工程:addcalldll
//libcall.h
#ifndef LIB_H
#define LIB_H
extern "C " int _declspec(dllexport) add1(int x, int y);
#endif
//libcall.c
#include "libcall.h "
#include "..\\add\\add.h "
#pragma comment(lib, "..\\add\\debug\\add.lib ") //define static library
extern "C " _declspec(dllimport) int add(int x,int y);
int add1(int x, int y)
{
return add(x,y);
}
可是在build的时候出错:
Compiling...
libcall.c
c:\testlib\addcalldall\libcall.h(5) : error C2059: syntax error : 'string '
c:\testlib\addcalldall\libcall.c(4) : error C2059: syntax error : 'string '
如果建立一个exe工程调用lib的时候不会出错,难道dll中调用lib要使用什么特殊的处理吗?
//exe工程调用方式:
//main.cpp
#include <stdio.h>
#include "..\\add\\add.h "
#pragma comment(lib, "..\\add\\debug\\add.lib ") //define static library
int main(int argc,char* argv[])
{
printf( "2+3 = %d ",add(2,3));
return 0;
}
我看 < < VC++动态链接库(DLL)编程深入浅出(一)> >
静态链接库和动态链接库的另外一个区别在于静态链接库中不能再包含其他的动态链接库或者静态库,而在动态链接库中还可以再包含其他的动态或静态链接库。
不知那位大人能帮我看看?
------解决方案--------------------
首先纠正一下:静态链接库和动态链接库的另外一个区别在于静态链接库中不能再包含其他的动态链接库或者静态库,这句话是错的,静态库中可以再包含其他的库.
------解决方案--------------------
//libcall.c
#include "libcall.h "
#include "..\\add\\add.h "
#pragma comment(lib, "..\\add\\debug\\add.lib ") //define static library
--> > 把这个注释掉试试//extern "C " _declspec(dllimport) int add(int x,int y);