I wrote a library which is intended to be used in C as well.
Compiling the library to a .dll/.so/.lib itself is well documented and works as expected.
However, I cannot find anything regarding the corresponding header files.
The only documentation for something like this that I found, is the --header cli argument which was supposedly (to be?) removed.
Can't find it in the https://nim-lang.org/docs/nimc.html page, nor in the help-page of my installation.
Nim-Version:
$ nim -v
Nim Compiler Version 1.6.0 [Windows: amd64]
Compiled at 2021-10-19
In the documentation for the exportc pragma, it only explains the naming and how it can be used.
Same goes for the backend-integration Page, which also doesn't state anything helpful regarding header files.
Is there a proper way to generate the header-files from nim-source code, or do I have to write these manually?
You can use the Genny nimble package to generate a C header file (and also Python and Node.js bindings!) for your Nim library.
Besides that, writing the header manually would be the next best choice. Well, the --header option does still happen to work, but it's not recommended to use it as it's undocumented and unsupported.
Related
I have a situation where I recently added a bunch of pcap functionality to a shared library that I've written to do some packet sniffing/injecting stuff.
I installed the pcap stuff, i.e.
sudo apt-get install libpcap-dev
wrote all the code, then tried to build it with my makefile
All compiled and linked no problem
But when I looked more closely I noticed I hadn't specified -lpcap as a library dependency
But the linker hasn't complained about any undefined references..
So the question is how is the linker finding those pcap functions that I've called in my library code?
I was aware that if you use socket.h functions they're contained within the standard C runtime lib so you don't need to explicitly specify a library dependency. Is it the same for pcap?
Is there a way of querying where the linker has found its functions, i.e. where it found the pcap functions in this instance? I'd like to understand whats going on, rather than just being glad it worked..
To clarify, can you find the specific library file (.so or .a) that the linker has used when linking to a function that my code references?
possibly a verbose option to see exactly what the linker is doing?
I want to cross-build partprobe (e.g. parted-3.1 from [here] ) for an ARMv7-controller but keep getting error messages concerning libuuid and uuid_generate.
Actually I only need partprobe which may not even rely on that uuid_generate function, but I don't see any options in the configure script to disable any features.
I've successfully cross-built software before using the BPS as well as using the ARM toolchain provided by my distribution (Mint 17).
Here's what I've tried so far:
1) Using the manufacturer's BSP
I have a board support package that provides libraries and headers as well as a toolchain:
/path/to/bsp/_rootfs/lib/libuuid.so.1
/path/to/bsp/_rootfs/lib/libuuid.so.1.3.0
/path/to/bsp/board-support/linux-3.2.0-psp04.06.00.11/include/linux/uuid.h
/path/to/bsp/linux-devkit/am3352/bin/
When I invoke
./configure \
--libdir=/path/to/bsp/_rootfs/lib/ \
--includedir=/path/to/bsp/board-support/linux-3.2.0-psp04.06.00.11/include/ \
--bindir=/path/to/bsp/linux-devkit/am3352/bin/ \
--with-sysroot=/path/to/bsp/_rootfs \
--host=arm-linux-gnueabihf
I get the following error
checking for uuid_generate in -luuid... no
configure: error: GNU Parted requires libuuid - a part of the util-linux-ng package (but
usually distributed separately in libuuid-devel, uuid-dev or similar)
This can probably be found on your distribution's CD or FTP site or at:
http://userweb.kernel.org/~kzak/util-linux-ng/
Note: originally, libuuid was part of the e2fsprogs package. Later, it
moved to util-linux-ng-2.16, and that package is now the preferred source.
The uuid.h and libraries are available, so I thought the configure script should not complain, but the error seems to be misleading. The header uuid.h is available but does not contain a uuid_generate function declaration, while the library contains such a function (checked with nm -D).
I'm not sure what to do with that...does the BSP contain incompatible version of the header and the library?
However the busybox binary contains wget which seems to use uuid_generate...at some point it must have worked.
Replacing the original uuid.h with a uuid.h.in from the /path/to/bsp/docs/am3352/licenses/e2fsprogs/ (which contains uuid_generate) still results in the same error.
2) Using the Linux distro's ARM-environment
I also tried using the ARM-toolchain provided by my Linux distribution (packages gcc-arm-linux-gnueabihf, libuuid1:armhf)
aptitude install uuid-dev:armhf
shows conflicts with the x86 package of uuid-dev, but there are already available:
/usr/arm-linux-gnueabi/include/linux/uuid.h
/usr/arm-linux-gnueabihf/include/linux/uuid.h
/lib/arm-linux-gnueabihf/libuuid.so.1
/lib/arm-linux-gnueabihf/libuuid.so.1.3.0
BTW: None of those two header files includes a string uuid_generate, while the libraries do.
Invoking
./configure host=arm-linux-gnueabihf
runs without errors, but creates a Makefile that lacks any info on the cross-build environment.
BTW: Invoking make anyway exits with error; trying the same with the current source code from git://git.savannah.gnu.org/parted.git configures and builds successfully, but no magic involved: the result are libraries/binaries for x86 and not for ARM.
Right now I'm at my wits' end - so my question is:
Can someone see the problem(s) I'm missing?
I was having a lot of trouble getting code completion to work in QtCreator 3.0.1 on ubuntu 14.04.04LTS.
I went to the QT creator website and downloaded the latest version 3.6.1 and I think I've identified the issue but don't know how to fix it.
To replicate, I go to "File|New file or project|Non-Qt project|Plain C App
Then make a test.c file, qmake build system, i leave the "desktop kit" checked, and start.
As you can see here:
It can't find stdio.h
But if I specifically write:
#include "/usr/include/stdio.h" everything works!
The only place i can find an include path to search is in Tools|options|C++|File Naming -> Search paths and /usr/include is already there.
I've tried a C++ blank project just in case it only works for C++ files but it can't find the search path there either. Is there a setting somewhere else that's missing or wrong so I can use the standard naming scheme?
Ah! Found it. So the "Desktop Kits" for some silly reason never had a compiler selected even though during setup it automatically detected clang. Anyways, when I selected it from the Tools|Options|Build & Run|Kits tab|Desktop (default) and selected the compiler from the pulldown box code completion is working again.
I am using an open source CLI parser (this one -> http://sourceforge.net/projects/cliparser/) to add command line interface to my application and it works really neat on its own, but I am having trouble adding it to my application. The documentation provided is very meager and I have limited experience with makefiles. If anyone has used this parser before could you help me out with it?
Specifically, how do I make the parser run within my program? The document says"link your parser against libparser.a" What does that mean?
Thanks!
When you compile your program, you need to link against the library. If using GCC, this is done via two ways:
You can specify the path to the library:
gcc myapp.c /somepath/libparser.a
Or, if it is in your standard library directory you should be able to do:
gcc myapp.c -l parser
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.