SQLite & C++ in Code::Blocks, -l -pthread mystery

I'm trying to move things from Windows to Linux, with SQLite, but things are not 1:1.

I can use sqlite3 from terminal.

Using this Sqlite tutorial: https://www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm
(the -l is shown in the build for C++ comment...)

With below simple console app:(<> Code format does nothing, ?)
-- Code --
include <stdio.h>
#include <sqlite3.h>

int main(int argc, char* argv[])
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;

rc = sqlite3_open("test.db", &db);

if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
return(0);
}else{
fprintf(stderr, "Opened database successfully\n");
}
sqlite3_close(db);
}
-- Code --

I'm not able to interpret following error on compile:

/usr/bin/ld: cannot find -l -pthread
collect2: error: ld returned 1 exit status

There is no file named 'pthread' or 'lpthread' that I have found.

Any advice appreciated.
Please try and be specific, I may have follow-up questions.
Last edited on
show your build command.
It should be only -pthread, not -l -pthread, not -l-pthread


> There is no file named 'pthread' or 'lpthread' that I have found.
/usr/lib/libpthread.{a,so}
I must admit, I can't find the actual build command within code::blocks.

In the Project build options, Debug and Release, Linker settings, Linker libraries is listed only: -pthread .

I did find Make Commands, build project target: $make -f $makefile $target

Edit:
I can compile from terminal, perfect every time. Using: g++ fetch.c -l sqlite3
Last edited on
> Linker settings, Linker libraries is listed only: -pthread
that would make it -l-pthread
put it in "Other linker options"

It should also be in
Compiler settings->Other compiler options
(the flag works also in the preprocessor)
man gcc wrote:
-pthread
Adds support for multithreading with the pthreads library. This option sets flags for both the preprocessor and linker.



> I can't find the actual build command within code::blocks.
Build log
(clean it first)
Ok,
That seems to have satisfied the -pthread.

Now I'm searching for reason for undefined reference errors in the sqlite3.c file.
'dlerror', 'dlclose', 'dlsym', 'dlopen', and collect2: error: ld returned 1 exit status.
Last edited on
man dlclose wrote:
SYNOPSIS
Link with -ldl

(<> Code format does nothing, ?)


How to use tags:
http://www.cplusplus.com/articles/z13hAqkS/

Select your code and press the <> button. It doesn't work when first posting, but it does after :+)
It looks like adding dl
in the Debug, Linker Settings, Link libraries solved this.

Thank you all.
Last edited on
Topic archived. No new replies allowed.