First steps with SQLite and C - c

i'm trying to use SQLite in C. I downloaded the precompiled Binaries for Windows from the SQLite-Homepage. I extracted them and added sqlite to my environment path var. Using the command line, everything works.
Now i trying to use sqlite in a simply C-Code. Many Tutorials showed me to beginn with:
#include <sqlite3.h>
But my Compiler can't find the the file. The same result, trying with:
#include "C:/sqlite/sqlite3.h"
I'm new at C but don't i need a Header-File (*.h) for the #include command? Because the downloaded sqlite package only consist of: sqlite3.def, sqlite3.dll, sqlite3.exe (shell).
Thanks for your help

To use SQLite, download the source (the amalgamation), and include sqlite3.c in your project, together with your other source files.
(The sqlite3.h file should be in the same directory.)

Related

Android Studio : include an other path in a c file

I develop an application on Android Studio, and I use the code of a C project. The 2 codes needs to be the same.
I have a C file myfile.c located in myC/abc/ with this :
#include "lib/myheader.h"
But myheader.h is located in myC/lib/
So the only way I found is :
#include "../lib/myheader.h"
But I need to keep the same code. So I can't change the file.
Is it possible? Anyone have an idea?
I use CMake to add C code to my project.
I fixed it. I add include_directories(src/main/myC) in my CMakeList.txt.

SDL and cygwin and sublime text C language

I am trying to use SDL with C language sublime text and cygwin
Basically i downloaded the SDL devel mingw32 tar thing and unzipped it
then i copied the includes to cygwin/usr/include as well as the lib from the unzipped file to cygwin lib
also i moved the SDL.dll to the directory where my file written in c is and i included it with #include "SDL.h"
when i tried to compile it i get this error
$ gcc -o sdl sdl.c
sdl.c:1:17: fatal error: SDL.h: No such file or directory
#include <SDL.h>
^
compilation terminated.
also this is the file i am trying to compile
#include "SDL.h"
#include <stdio.h>
int main(int argc, char *argv[]){
}
can anyone help me out with employing SDL in my programs? i dont know how to make it work and what is missing
The #include "SDL.h" line is making the compiler look for a header file called SDL.h. The SDL.dll file you've copied contains the SDL library's compiled code, but only a little bit of the information you need to interface with it. The rest of that information is in the SDL.h header file, which should be in a folder called include in the SDL-devel-*-mingw32.tar archive you downloaded.
You will also have to link your program to the SDL.dll file by adding -lSDL as an argument when you call gcc. I'm not entirely sure if gcc allows you to link directly to a DLL file, so you may also need the libSDL.dll.a file from the lib folder in the archive.
By the way, Sublime Text is just a text editor and should have little to no effect on how your code compiles.
Good luck!
okay i have found the solution
you need to actually build the file for cygwin by downloading the source file and make & make install
here is the guide
http://www.noquarterarcade.com/using-cygwin-for-sdl-development

Problems with linking lua statically

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.

assert.h missing when compiling with mingw

I am compiling C code with MinGW. The C code is a tcl package/extension.
(using the MinGW compilor, downloaded: mingw-get-inst-20111118.exe)
Compiling the code (e.g. the tcl package) works fine under linux.
I am running "./configure" and using the supplied "Makefile.in".
The problem is that the C code at some point includes "assert.h".
The other header files are fine, e.g. for "string.h" and "stdlib.h".
This is because the TCL sources include a subfolder called "./compat". In this filder the header files are located just in case they are not found somewhere else.
But in the "./compat" folder the file "assert.h" is missing. So I get an error.
I searched for the header file in "c:\MinGW\include" but I did not find "assert.h" there.
Either I copy my own "assert.h" in the "./compat" folder. Or I install some MinGW package that puts some "assert.h" in a subfolder of "c:\MinGW\".
=== SOLUTION: ====
c:\MinGW\include\assert.h
I was the hole time in front of me!!!
My bad! thx.
<assert.h> is part of standard C and included with the base dev package:
Did you download the dev package?
Did you download this?
http://sourceforge.net/projects/mingw/files/MinGW/Base/mingw-rt/mingwrt-3.20/
I don't know about the peculiarities of the tcl package, but if it includes its own assert.h. then you should include on on the Include path, along with the libraries that came with it.
Which IDE are your using?
It seems you downloaded only mingw partially. Download the full development package that is bundled with IDEs like Codelite and Code::Blocks.

How do I link libraries in Xcode 4?

I'm a complete beginner to Apple's Xcode, but I have followed the Xcode documentation and the advice of a few related questions without success.
I installed GMP to /usr/local/bin, wrote a short program using the library, and compiled with gcc main.c -lgmp. It compiled with no warnings or errors, and the executable worked flawlessly.
I started a new Xcode project (Command Line Tool; Type: C), copied the code to the newly created main.c, and opened the project build settings. From there I set Linking > Other Linker Flags to -lgmp and Search Paths > Library Search Paths to /usr/local/bin. However, the build fails with the preprocessor error "Gmp.h: No such file or directory".
I have tried almost every header imaginable:
#include "gmp.h"
#include <gmp.h>
#include "gmp"
#include "libgmp.a" . . .
This has been my main obstacle over the last three months which has prevented me from learning C. Any help leading me to an eventual solution would be greatly appreciated.
There's a few things you have to set up in your Xcode project. For example, I have gmp installed in /opt/gmp/5.0.2 and I will use that as an example. The actual library is installed into /opt/gmp/5.0.2/lib and the header files into /opt/gmp/5.0.2/include. When installing the library setting the --PREFIX flag to /opt/gmp/5.0.2 would handle this automatically. If you don't set this flag the prefix is usually set to /usr/local by default.
The Other Linker Flags looks right, it should be the name of the library.
Set the Header Search Path to the include directory, in my case /opt/gmp/5.0.2/include.
Set the Library Search Path to the lib directory, in my case /opt/gmp/5.0.2/lib.
Since the header search path has been set, you should now be able to include the header file like this:
#include <gmp.h>
Of course, replace /opt/gmp/5.0.2 with the PREFIX path you used when you installed gmp.
Lastly, you typically don't install libraries to /usr/local/bin, you would install to /usr/localand let any binaries be installed into bin while libraries like these would be installed into lib. Of course any path scheme would work, I usually recommend /opt/<project-name>/<version-number> since it allows me to keep better track of what I have installed and have multiple versions of the same libraries and tools without having to deal with collisions.
I have updated my system from snow leopard to mountain lion and had to install gmp.
First of all I have installed Xcode CommandLineTools set.
Secondly, installed Homebrew. Then with it I have done steps in this topic: https://apple.stackexchange.com/questions/38222/how-do-i-install-gcc-via-homebrew
In my last step, made changes to an xcode project as colleague Marcus Karlsson told.
It's finally working! Very big Thank You :)

Resources