I'm trying to link lua statically into my C++ application with VS2012. I downloaded the vs11_lib files off of sourceforge and added linker dependencies for this file, lua52.lib. I'm now getting all sorts of link errors when I try to compile and I'm pretty sure I missed a step. Again, I'm doing this statically since I'd like my application to run stand-alone. Any pointers would be greatly appreciated!
The best way is to build embeddable Lua yourself. Download source files for your desired version, create a static library project in VS2012, copy the source files (*.h and *.c to the VS project, not VS solution) and add all source files to the project, except luac.c and lua.c, which are needed for standalone executable rather than embedded library (and they conflict with each other in one project anyway).
After that compile the release version and you got yourself lua5.x.lib that you can link against. If it's still not working, then the problem might be that you added linker dependencies in the wrong place.
Lua sources can be compiled as C or C++. I figure the lib files you are trying to use are compiled as C and you are including their headers as C++. The outcome would be that the names of the functions are different; ergo, the linking errors.
If you are using a C lib in a C++ file, wrap the lib's header like so:
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
For more detailed instructions using Lua with Visual Studio, see this article.
UPDATE:
As, #lhf says in a comment, the newer distributions of Lua provide a C++ header lua.hpp which does the same thing. It is described for older distributions in PIL.
Related
I am attempting to run an old program that uses tcl as well as legacy opengl. I managed to link the opengl libraries successfully; however, I cannot seem to get the tcl linker to work. For context, the program I am using came with include and lib folder. The lib folder contains tclstub86_32.lib, tclstub86_64.lib, and tkstub86.lib as well as opengl .libs. The include folder contains two folders: tcl_include and tk_include, which obviously contain all the .c and .h files for tcl and tk. The following pictures show my settings from using project -> build options:
The error I receive when compiling is:
C:\Users\amlut\Downloads\C\tkogl\curve.c|18|undefined reference to `_imp__Tcl_Free'|
And here is the bit of code that is throwing the error:
if (*line != NULL) Tcl_Free((char*)*line);
I am not sure what I am doing wrong here, any help is appreciated. Thank you.
The problem is that the code is apparently linking against the Tcl stub library (an ABI/API adaptor library) but isn't compiling to use that library but rather to use a full Tcl library instead. When building an extension package, using the stub library is a good thing as it means that the resulting code is not bound to an exact version of the Tcl (and Tk) library but rather to a version of the Tcl ABI which has a much longer support cycle.
The fix is to define the USE_TCL_STUBS and USE_TK_STUBS (that has the identical issue; you have just hit the Tcl version of it first) C preprocessor symbols when building; set them both to 1 and recompile. This is done under the Compiler Settings tab in Code::Blocks apparently.
There is a lib-sys for libvips on crates.io, however it uses pkg-config which searches the system for the library to link to dynamically, not statically.
I want to provide libvips with the final binary of my software in .dll or .exe along with it since the user should only install one executable with everything in it, C and Rust code.
Looking at the Rust book's FFI linking section, we can link lib.a files easily, but libvips is a huge complex C library that has releases for Windows in .dll and .exe format. I do not know how to link these Windows binaries of libvips to a Rust program statically.
Potentially, I could build it from source manually and link it manually, but the build process seems very complex and it uses scripts and Docker. I would have to replace those scripts with a build.rs of my own that did the same but that seems very hard to me since I'm a beginner at this. I know I would have to set rustc-link-search in build.rs, but I don't know how to compile the .a files for libvips. Rust book on this
My goal is to FFI into libvips from Rust. I am using Windows 10 and want to cargo build the project and have the Rust code and libvips in one distributable binary with no other dependencies.
edit-1:
the vips-dev-w64-web-x.y.z.zip contains libvips.lib , libvips.dll.a files, pkgconfig .pc files, as well as the normal .dll and vips.exe. Can i use these .lib and .a files and if so exactly how? Will it link statically? Are these .pc files useful for my situation?
Just ship the libvips bin area in your tree somewhere, add it to PATH on startup, and link dynamically. This is how electron apps and node.js packages that use libvips work. Static linking for complex libraries died a while ago, it's not worth trying.
As much as anything, it would be a potential licence violation. libvips is LGPL, so you MUST link dynamically (or include enough of your code to allow relinking), or your whole application becomes open source.
I want to my make own library and have it use the same syntax as the standard C libraries as in
#include<mylib.h>
So that it looks like #include and some of the libraries that are included with C.
Can I make the library static as opposed to linking so that I can compile it in GCC without additional arguments, as if I were using another library like stdio.h or string.h?
This seems simple enough.
Develop the library (create as many source files as you need).
Build the source files into a shared library (.so) using a tool like CMAKE (which i strongly recommend).
Copy that library to your library path (i.e. /usr/lib)
Later on, all you have to do is import your lib: (i) in the source using #include<mylib.h>; (ii) when building (also using CMAKE) or using the flag (-lmylib) in the GCC compiler: gcc -lmylib myfiles.c -o myoutput.
In addition to #include "mylib.h", you need to add -lmylib command line to the compiler (more specifically linker) when using the library. I assume that the your library archive created through ar command is named as libmylib.a.
Usually, we do not write 'manually' build instructions, but we rely on tool that generates build chains. There are quite a lot of them, the most know are probably autotools and cmake (under Linux).
I would suggest you to have a look to cmake examples and/or documentation to get your code built.
There are quite a lot of differences between static and dynamic libs, and you will also need to package somehow your lib if you really want to use it like 'standard' lib (like libxml2, openssl, etc.)
A lot to say about it, but you should first have a look to 'how to build' your lib, and then see how to make it easy to use, IMHO.
I am currently trying to import some libraries into my Gwan C script. I have read through the manual and am using #pragma include to include the folder that my libraries are in, and then use #pragma link to actually include the libraries, but when I run the script it error and says /usr/bin/ld: cannot find -lxxxx.a
Heres current code
#pragma include "/opt/Gwan/libraries/xxx"
#pragma link "xxxx.a"
current Gwan version 4.3.11. Thanks, any help will be appreciated
[EDIT]
All is working fine now, changed all my libraries to shared and placed them in /usr/lib
While you can link object code and static libraries with G-WAN scripts, you should rather use a dynamic library because it will only be loaded once in memory.
Do you succeed in running the (many) G-WAN examples that use third-party libraries?
(libsqlite, libcairo, libmySQL, libcURL, liboauth, libmemchached, ImageMagick, etc.)
Don't forget that you must indicate the library file name without the starting "lib" prefix (ie: sqlite3 for libsqlite3.so).
Also, libraries compiled for 64-bit won't work with G-WAN 32-bit (and vice-versa).
If this can help, there's a G-WAN FAQ dedicated on libraries which gives tips and tools to check for possible problems.
Maybe you should give the whole library names instead of the xxx in your example.
I have to use LU decompostion to fit a simple model to some data (simulated) in C. An example of what I need to do is here:
However, I'm stuck with a more basic problem: how do I install packages in C and call them in my code?
I'm new in C and I'm used to R. But I have this assingment to do some tests about Matrix inversion, LU decomposision and the professor suggested using Lapack to easy things (thus, I don't need to code myself the LU decomposition etc.). But I don't know how to install the package and call it in my code, in order to use the functions of LAPACK.
I have a windows 7 64 bits and I'm using compiler Code Blocks 8.02
Thanks for any help.
Normally you don't "install" C libraries in that sense. Normally, in Windows you have three types of files. The header files, typically ending in .h, the dynamic library, .dll, and most likely some linker files (typically, .lib, .a or something). The linker and compiler will need to be able to find these files somewhere. Normally you set the include directory paths, and library directory paths.
E.g. Let's say you downloaded a library called foo, and you extract it to C:\foo.
In that folder, libfoo.a, foo.dll and foo.h reside. In Code::Blocks you will have to point include directory path to C:\foo and library path to C:\foo so that the linker and compiler know where to look for these files. Since you're linking against the foo library, you will also have to set -lfoo or something similiar in linker command line. This is GCC syntax, but I think Code::Blocks uses GCC compiler behind the scenes anyways.
In the C code you can just #include <foo.h> and the compiler will find it for you.
You need to install that library and it might actually supply a tool for that. Check their documentation (e.g. a file INSTALL or README in their distributed sources). If the library uses only headers you might only need to copy it's headers to some directory on your system, but their buildsystem might be able to do that for you.
Once that is done you would tell your IDE on where to look for the sources and if the library uses not just headers to link against the actual library file. See the documentation in the Code::Blocks Wiki on how this is done for some example cases and adapt for your library.
The simplest thing to do in your situation is to install Cygwin. You can use the setup.exe installer to install the GCC and the LAPACK libraries. When you want to use the LAPACK library, you will add the -llapack option to your GCC command line.