How to use sqlite3.c and sqlite3.h in eclipse C/C++ project - c++

I am trying to use amalgamated version of sqlite3.c and sqlite3.h in my C/C++ project. It has code in both C and C++. I am using eclipse IDE in UBUNTU 12.04.
Now my problem is that after having include sqlite3.h in my file where I need sqlite3.c functions and having added ld and pthread libraries in linker, i am still getting errors and cant build the project.
This is weird and should not happen. Please take a look at following screenshots that explain my problem.
************************************************************************************
************************************************************************************
What am I missing?
Please Help!
Thanks

Make sure that the pthread library is linked before the dl library.
In other words, your compiler command (as generated by Eclipse) should be:
gcc shell.c sqlite3.c -lpthread -ldl
and not
gcc shell.c sqlite3.c -ldl -lpthread
See here for a correct command line:
http://www.sqlite.org/howtocompile.html

Related

missing minGW files

I am trying to run a test for my class, but my build.bat did not build correctly.
It says ld.exe is missing in minGW folders.
I already tried to reinstall minGW.
C:\Users\HHT\lab_00\build>g++ -std=gnu++11 -o testB ../_tests/_test_files/testB.cpp ../includes/stub/stub.cpp ../includes/array_functions/array_functions.cpp -Igoogletest/googletest/include
-pthread -Lgoogletest/build/lib -lgtest
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
No, it says the library pthread cannot be located.
ld(.exe) is the linker complaining it cannot find it.
Provide proper path to library with -Lmysuper/secret/path/to/location or have the location in PATH in Windows.
I just found out that I missed one of the installations in minGW.
It all good now.

Compiling examples from GLFW?

I am trying to compile the file simple.c in glfw-3.2.1/examples on Ubuntu 18.04. I am using the following compilation command:
gcc -o simple simple.c glad.c -lglfw3 -lGL -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread -ldl -lXinerama -lXcursor
I have copied and pasted glad.c and glad.h into this examples folder, as well as the include folder that came with glad.zip
However, I when I try to compile the code I get the following:
glad.c:25:10: fatal error: glad/glad.h: No such file or directory
#include <glad/glad.h>
I don't understand why this is, since I am including glad.c in the compilation command.
I am following this tutorial to set up glad https://learnopengl.com/Getting-started/Creating-a-window. Unfortunaly, this opengl tutorial is geared towards MS Windows. Is there an easier way to set up glad on Ubuntu (sudo apt install ...)?
What am I missing here?
Thanks
Including glad.c in the compilation command will not bring the header in, it will compile glad.c and bring in the object from the generated file in (so it would be somewhat close to -lglad if you had installed some glad library)
Unfortunately there does not seem to be any ubuntu package for glad, the next simplest thing would be to simply compile the examples along with glfw (just run cmake and make in the glfw folder), but we can fix that anyway.
Understanding the error
glad.c:25:10: fatal error: glad/glad.h: No such file or directory
#include <glad/glad.h>
says "the file glad.c wants a header located in glad/glad.h, but I cannot find it"
This can either be a problem with include paths (gcc is not looking in the directories you intended it to look at), or the file really is not here.
Looking at glad.c and simple.c, they use this syntax:
#include <glad/glad.c
Includes can be of two kinds, either through double-quotes in which case they are called "local includes" and gcc will look for the headers in the current directory, or with angle brackets and they are usually "system includes"; you need to tell gcc where to look for them with the -I option
Fixing it
There are multiple ways to fix that.
We can use a command line/environment the c files expect.
First, respect the zip hierarchy, the post you linked to says there should be two include directories, so you need to put the headers where they were in the zip file (glad.h in the glad directory) ;
then tell gcc to look for include files in the current directory with -I. (. is the current directory)
The command line will then look like something like gcc -o simple simple.c glad.c -I. -lglfw3 -l...
or
change simple.c and glad.c to include "glad.h" instead of <glad/glad.h> ; the files will then look for the file where you had it automatically.
Having tried to compile simple.c the same way you did now, you will also need a linmath.h header; I am not sure if it comes with glad but glad and linmath.h are in the deps directory of glfw in the git tree, I would assume they also are in the tar.

libxml/parser.h: in c++ ubuntu

Even though I have installed libxml++2.6-2 libxml++2.6-doc etc in my ubuntu 12.04 version again I am getting the below error
fatal error: libxml/parser.h: No such file or directory
I am using make for building the project
Kindly suggest any other libxml libraries which I need to install
libxml/parser.h is a part o libxml library, not libxml++
For any given library, you need development packages (the ones with names ending in -dev) in order to build applications using that library.
You need to pass additional flags to your compiler: xml2-config --cflags and to linker xml2-config --libs.
I don't have access to an Ubuntu system now, but: Maybe you need to install the libxml developer package? Maybe you only have the library but not the include file(s)?
Check in /usr/include, /usr/local/include, ... for the directory libxml and the file parser.h.
If you find the file, you may need to adapt your makefile so that the parent-directory is in the list of include paths, e.g.:
INC = -I/usr/local/include
g++ $(INC) ...
If you did not find the file: Check the available libxml packages for a developer package and install that.
Before Posting the answer THANKS to the people who have answered, but those answers were not worked for me
I have just copied libxml folder from the directory usr/lib/libxml2 and pasted in usr/lib directory and compiled my code it is not giving any error. It is working fine now.
Please read #el.pescado answer before reading this. I wanted to comment on that answer but felt the need to format my code better.
gcc -c <files to compile> `xml2-config --cflags` -o <object files>
gcc <object files> -L<libxml2 lib location> `xml2-config --libs` -o <binary file>
Assuming we have a file names xmltest.c that have code that included libxml2 header like #include <libxml/parser.h>, standard location of libxml2 shared library i.e. /usr/lib64/libxml2, the above code will evaluate like this:
gcc -c xmltest.c -I/usr/include/libxml2 -o xmltest.o
gcc xmltest.o -L/usr/lib64/libxml2 -lxml2 -lz -lm -o xmltest
A better idea is to put together a Makefile that does this automatically.

How to build and run Concorde TSP solver

I'm making a code in C++ that shoudl use a library that is called Concorde to solve a well known problem called Traveling Salesman Problem. This library is available here
I've compiled by first running ./configure --with-cplex=<CPLEX_DIR> and then make resulting in two main files concorde.a and concorde.h. In this way concorde is configure to run and use IBM Cplex as the exact solver.
I'm using Code::Blocks as IDE and in the build options I've added the library (concorde.a) under Link libraries and included the header in my code.
However when I try to compile my code, it gives me and error indicating that it can't find the implementation of the concorde functions that I call and that are defined in the concorde.h file. In this case the error is "undefined reference to <function>".
Can anyone help me with that?
The last part of the build log of codeblocks is the following:
g++ -L/opt/ibm/ILOG/CPLEX_Studio1251/cplex/lib/x86-64_sles10_4.1/static_pic
-L/opt/ibm/ILOG/CPLEX_Studio1251/concert/lib/x86-64_sles10_4.1/static_pic
-L/opt/concorde -o bin/Debug/SVRPDSP obj/Debug/instance.o obj/Debug/lib/combo.o
obj/Debug/lib/IncumbentCallback2C.o obj/Debug/lib/lazyCallback2C.o
obj/Debug/lib/lazyCallbackGLS.o obj/Debug/lib/lib_algorithms.o
obj/Debug/lib/lib_general.o obj/Debug/solution.o -lrt -lilocplex -lcplex
-lconcert -lm -lpthread /opt/concorde/concorde.a
ps: I'm compiling on Ubuntu 13.10
Thanks.
First of all: Concorde does not support CPLEX 12.5.
I have downloaded QSopt and launched ./configure --with-qsopt=QSOPT_DIR.
Finally, the order of the libs is the following:
-lilocplex -lconcert -lcplex /opt/concorde/concorde.a /opt/QS/qsopt.a -lm -lpthread

Help on build using g++ on Windows

There is a small project C++ (it has win32 code) that I need to build. It already has its Makefile. I was told to use MinGW. I have never used it before. I downloaded and installed the latest MinGW installer.
Then, I opened the MinGW shell and did make. The exe file was created. But when I try to run it I get libgcc_s_dw2-1.dll is missing! Why do I get this error? Shouldn't the exe be self-contained and run anywhere?
UPDATE
Here's more information, from the Makefile:
CC = g++
CCOPTIONS=-DWINDOWS -DFORCEINLINE -DMINGW -DSRTP_SUPPORT -D__EXPORT= -D_WIN32_WINNT=0x0501 -DNOMVS
setup.exe: setup.o common.o
$(CC) -ggdb -g -O0 -o $# setup.o common.o -mno-cygwin -mwindows -lwsock32 -lws2_32 -lwinmm -lgdi32 -lcomctl32 -lmapi32 -lVfw32
Whether or not the exe should be self-contained depends on how you built it. We need to see the commands that were executed, or post the makefile. But that DLL does not seem to be part of the current version of MinGW. Also, please clarify if you are actually doing this under cygwin, or if you added the tag by mistake.
Edit: A bit of googling seems like it has to do with the horrible "official" MinGW installation. Remove it, and download the Twilight Dragon build from http://tdm-gcc.tdragon.net and then rebuild completely. The "official" build is cr*p anyway - I don't know why anyone uses it.
If what you want to do is a stand alone application with MinGW, you should add -static to the linking options.
On a side note, if you're making a Win32 application, add the -mwindows option to the C++ compiler so it doesn't open a console together with your main window.