On 18 July 2013 17:34, Peter M <lua4...@gmail.com> wrote: > Hello, > > I'd like to use C++ in my luarock "refser". However, I've met some > problems with compiling it with built-in build back-end. > > (Long text ahead, to cut it short: Visual Studio compiler needs a > special option to compile C++, but built-in system can't provide it) > > The first problem is that it uses gcc instead of g++ even though > source file extension is .cpp. I looked up a solution and added stdc++ > to the libraries list of my module in the rockspec. > > However, this approach fails on windows as Visual Studio > compiler(cl.exe) obviously can't find stdc++.lib, it compiles C++ fine > without it(not really, see below). The solution I've found is to use > platform overrides and provide an empty table for field "libraries" in > the rockspec. On this stage it looks like this: > http://raw.github.com/lua4web/refser/90fe/rockspecs/refser-git-1.rockspec > (I think I should add "windows" into platforms table) > > Umfortunately, this is not enough as proper compiling C++ with cl.exe > requires passing /EHsc option. I've tried fixing that with a hack, by > adding /EHsc to the incdirs field in the rockspec: > http://raw.github.com/lua4web/refser/60f8/rockspecs/refser-git-1.rockspec > But that didn't work. Compiler just ignored the option. > What's really strange is that when I manually copied command executed > by luarocks: > >> cl /MD /O2 -c -Fosrc/crefser.obj -Ic:/LuaRocks//2.0/include src/crefser.cpp >> -Isrc/ /EHsc > > and executed it manually in the command line prompt, it worked as expected. > > I know that I can just use make or cmake, but built-in system works > really well to avoid any platform incompatibilities, and it's much > cleaner, so I hope I'll find a way to use it for C++, too. > > I can think of two ways to solve the problem. The first is to extend > rockspec format for built-in system and add "options" field: a string > or an array of strings to be passed to compiler after other > parameters. It could also used to override some options(i.e. use > different optimisation level). > Another solution I can think of is to add some basic C++ support into > luarocks. It could automatically provide -lstdc++ option for gcc and > /EHsc for cl and whatever other compilers might need for .gcc source > files. > > Both of my suggestions are not backward-compatible, so they might be > implemented in the 2.1 version.
Both suggestions are useful (though the first one may make it easier to accidentally make rocks less portable -- maybe the 'options' entry could be allowed only inside 'platforms' sections to make that more evident). But my plan was to release 2.1.0 "real soon now" (release candidates are already out there) so I don't know if it's a good idea to go implementing this now, but maybe we could start speeding up the release cycle and get 2.1.0 out now and 2.2.0 with improvements to the builtin backend not too long after that. Existing versions already check for the rockspec_version variable in rockspecs, so things shouldn't break silently, and the plan is to make LR easier to upgrade from 2.1.0 onwards. > Yet I hope to find a solution for > existing luarock version. I'm not sure if this is possible with the builtin type from existing LR versions. But if you *had* to make it work, one extreme workaround would be to: 1) fork luarocks.build.builtin and add C++ support 2) call this new module luarocks.build.cpp and publish a rock called luarocks-build-cpp 3) specify "luarocks-build-cpp" as a dependency in the refser rockspec 4) use build.type="cpp" in the rockspec This should work because build types are loaded dynamically, but currently LR does differentiate between build and runtime dependencies, which means that every user of your rock would have to install luarocks-build-cpp even if they're installing a precompiled rock. -- Hisham http://hisham.hm/ ------------------------------------------------------------------------------ See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk _______________________________________________ Luarocks-developers mailing list Luarocks-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/luarocks-developers