How to reference .cpp files without including them

2019-03-02 04:20发布

问题:

I'm trying to compile this code:

extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}

#include <luabind/luabind.hpp>
#include<iostream>
int main(){
   lua_State*pL=lua_open();

   luabind::open(pL);

   lua_close(pL);
   return 0;
}

But I don't have a .lib of luabind, so I use the source with the .h/.cpp files. The way I do it is by adding the directories to include, but I get a link error. The only way I can compile is by adding the .cpp files as existing elements, but the solution tree gets messy with the additional files. Can somebody tell me if there's a way to add the directory of the additional .cpp files in the solution's properties?

Thanks

回答1:

Compile the lua cpp files into a static library. Add the directory where you put those under "linker | input | additional library directories".



回答2:

You need to tell the linker where to find the functions referenced by the .h files (the .lib file, typically).