Compiling and embedding lua into a C++ application - compilation

For portability reasons, I'd like to compile lua from source when I compile my C++ code. I use lua to read input file.
If I understand correctly, lua's readme mentions that it's possible to do that through src/Makefile. I can't really read it that well. Has anyone figured out how to do it?
is it possible to have it in one command? gcc ....
bonus: how to put it in cmake ?

Lua has a makefile that needs your target platform to build to so you will need to specify make [target platform].
But that is right in the beginning of the readme.
You could try to call the make command from inside your build process.
Cheers
[UPDATE based on the comments]
If you use:
make a PLAT=[target platform]
on the command line in the src directory it will only build the liblua.a library for the target platform then you will just need to copy that file to wherever you need and link against it.

Related

no pdcures.dll created when using make -f Makefile for win 10 pdcurses

I have been trying to install PDcurses on my Windows 10 machine. The README.md says to run: make -f Makefile to build pdcures.dll in the 'wincon' folder. However when i ran this in Powershell it did not create any .dll, instead creating many .o files.
Then i tried to run 'make -f Makefile.wcc' in Powershell and it returned the error 'makefile.wcc:9: *** missing separator. Stop.' I got similar errors using Makefile.bcc and Makefile.vc.
What am i doing wrong here? Am i supposed to build one of the .c files?
Each of the Makefiles is compiler-specific, as described in the README.md. There's no reason to try Makefiles intended for compilers other than the one you're using.
The Makefile doesn't build a DLL, by default -- only a static library (ending in .a or .lib). PDCurses is a small library, and there's not much benefit in building it as a DLL. But if you want to, that procedure is also described in the README.md. In short:
make DLL=Y
but please read the file for details. Note that, even if you build PDCurses as a DLL, you'll still also need the .a or .lib file to link against.

How can I get all the compile commands from Xcode?

I am working on OCLint, and OCLint need all the compile command to do the lint job. now OCLint using xcpretty to parse xcodebuild.log to get the compile commands. So, I have to build the project even I only want to lint few source files. I wonder is there anyway to get the compile commands other than parse the xcodebuild.log?
One way of doing it is to write a wrapper for clang and linkers.
Using this answer: How can I force Xcode to use a custom compiler? you can redirect Xcode to compile your code with your own "clang" which might be a python shell script. This script would just grab a command passed to it and dump it to some file.
One detail though: if you use custom CC Xcode will also try to use it for linking C/C++ files this is why your script has to do nothing if it is called in a linker mode.
I have used this technique for another task: compiling my whole project with -emit-llvm flag to get all my code as LLVM bitcode. The example of a similar Python script can be found here.
Start by writing "hello world" script. Tell Xcode use it as CC, run your project and see the "hello world" string in your build log. From there you will know how to proceed.
I just use the -dry-run and regexpr to filter the compile commands. The -dry-run said,
-dry-run do everything except actually running the commands
The performance is just ok.
And it will be great if xcode provide one. They will be the only who can do this, and I think it is pretty usefull.

nmake or makefile cannot find directory

Hello I'm trying to build intel's tbb (threaded building blocks) from source. I have downloaded and extracted the source. I point visual studio's command prompt to the directory of extraction, where there is a makefile. I have edited the tbb_root variable inside the make file to point at the extracted directory, but when I tried running it I get
Makefile(28) : fatal error U1052: file '$(tbb_root)/build/common.inc'
not found Stop.
Lines 27 and 28 of the make file are as follows (all previous lines are comments/whitespace)
tbb_root=c:/tbb_extract/tbb42_20140122oss
include $(tbb_root)/build/common.inc
I have verified that c:/tbb_extract/tbb42_20140122oss/build/common.inc exists, so why does this fellow not make!
Thanks
Thomas
You need to use GNU make in order to build TBB from sources; nmake is not supported, and never was.
I'm not very familiar with nmake but according to the documentation it doesn't use include to include files. Try using !INCLUDE instead.
The answer was simple one - the file seems to of been assembled a kind of half GNU half VS-style makefile. It was a cannibalisation and I don't think it was ever tested.

Cmake: How to hold off finding libraries?

I have a Cmake project where I use static libraries from another project (which uses its own unique build system).
I have a bash script set up which compiles the libraries.
The problem arises when a new user checkouts both project. The new user cannot do cmake until the libaries are properly compiled in the other project, and the cmake command find_libarary cant find them.
I made the bash script part of cmake by using the command add_custom_target. But the issue is that it only execute if you do a "make".
Is there a way I can make CMake execute a command while its generating a build system. Or a better way would be to have it ignore the find command until the actual make?
Thanks
Why not LINK_DIRECTORIES(xxx) to the library folder and don't use find_library at all.
Sure, execute_process() function.

Passing C/C++ #defines to makefile

I develop C/C++ using the Eclipse IDE. Eclipse also generates a makefile which I don't want to edit as it will simply be overwritten.
I want to use that makefile for nightly build within Hudson.
How do I pass #defines which are made in the project file of the IDE to the makefile ? (and why doesn't Eclipse already include them in the generated makefile?)
I actually had this figured out once, then accidentally overwrote it :-( But at least I know that it can be done...
If you are running make from the command line, use
make CPPFLAGS=-DFOO
which will add -DFOO to all compilations. See also CFLAGS, CXXFLAGS, LDFLAGS in the make manual.
You could write a small program to include the headers and write a makefile fragment which you include in the main makefile (requires GNU make).
This is a fairly ugly solution that requires a fair amount of hand hackery. More elegant would be to parse the project file and write the makefile fragment.
For GCC use -D define.
OP commented below that he wants to pass the define into make and have it pass it on to GCC.
Make does not allow this. Typically you just add another make rule to add defines. For instance 'make release' vs 'make debug'. As the makefile creator you make the two rules and have the defines right in the make file. Now if Eclipse is not putting the defines into the makefile for you, I would say Eclipse is broken.
If you're using autotools another options is to have 2 directories 'bin/debug' and 'bin/release'.
# Simple bootstrap script.
# Remove previously generated filed and call autoreconf.
# At the end configure 2 separate builds.
echo "Setting up Debug configuration: bin/debug"
../../configure CXXFLAGS="-g3 -O0 -DDEBUG=1"
echo "Setting up Release configuration: bin/release"
cd bin/release/
../../configure CXXFLAGS="-O2"
Setup Eclipse. Open the project's properties (Project->Properties->C/C++ Build->Builder Settings) and set the Build Location->Build Directory to
${workspace_loc:/helloworld/bin/debug}
Replacing 'helloworld' with your project's directory relative to the workspace (or you can supply an absolute path ${/abs/path/debug}). Do the same thing with the Release config, replacing "/debug" with "release" at the end of the path.
This method seems like a waste of disk space, but a valid alternative to achieve completely separate builds.

Resources