What is needed:
Compile the json1 extension for SQLite
What I did:
Reaserched the official extension page: https://sqlite.org/loadext.html
Downloaded the SQLite source code: https://www.sqlite.org/cgi/src/doc/trunk/README.md
Found 2 ways to compile a dll:
cl windows command
gcc linux command
For the cl command I installed Visual Studio and launched the vcvars32.bat file for the enviroment launch, then tried this command: cl ext/misc/json1.c sqlite3ext.h /link /dll.
Docs: https://learn.microsoft.com/en-us/cpp/build/reference/compiler-command-line-syntax?view=vs-2019
However it didnt work and I got an error: fatal error C1083: sqlite3ext.h: No such file or directory.
I have the sqlite3ext.h file and tried moving it arround but nothing worked.
Then I moved to the gcc command:
I used the Ubuntu wsl
Upadated Ubuntu
Downloaded the source code (mensioned above)
Installed the SQLite developer package (can't find it)
Used this command: gcc -g -shared sqlite/ext/misc/json1.c -o json1.dll
Found the command on the SQLite extension page mensioned above
It didn't work and I got this long error message:
sqlite/ext/misc/json1.c: In function ‘jsonEachConnect’:
sqlite/ext/misc/json1.c:2099:29: error: ‘SQLITE_VTAB_INNOCUOUS’ undeclared (first use in this function); did you mean ‘SQLITE_STATIC’?
sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
^~~~~~~~~~~~~~~~~~~~~
SQLITE_STATIC
sqlite/ext/misc/json1.c:2099:29: note: each undeclared identifier is reported only once for each function it appears in
sqlite/ext/misc/json1.c: At top level:
sqlite/ext/misc/json1.c:2501:3: warning: excess elements in struct initializer
0 /* xShadowName */
^
sqlite/ext/misc/json1.c:2501:3: note: (near initialization for ‘jsonEachModule’)
sqlite/ext/misc/json1.c:2529:3: warning: excess elements in struct initializer
0 /* xShadowName */
^
sqlite/ext/misc/json1.c:2529:3: note: (near initialization for ‘jsonTreeModule’)
sqlite/ext/misc/json1.c: In function ‘sqlite3Json1Init’:
sqlite/ext/misc/json1.c:2594:8: error: ‘SQLITE_INNOCUOUS’ undeclared (first use in this function); did you mean ‘SQLITE_IGNORE’?
SQLITE_INNOCUOUS;
^~~~~~~~~~~~~~~~
SQLITE_IGNORE
sqlite/ext/misc/json1.c:2602:10: warning: implicit declaration of function ‘sqlite3_create_window_function’; did you mean ‘sqlite3_create_function’? [-Wimplicit-function-declaration]
rc = sqlite3_create_window_function(db, aAgg[i].zName, aAgg[i].nArg,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sqlite3_create_function
sqlite/ext/misc/json1.c:2603:34: error: ‘SQLITE_SUBTYPE’ undeclared (first use in this function); did you mean ‘SQLITE_CANTOPEN’?
SQLITE_SUBTYPE | enc, 0,
^~~~~~~~~~~~~~
ANY HELP WOULD BE GREATLY APPRECIATED!
Thanks!
I had this problem with the SQLite UUID extension using "better-sqlite", but that's something else. What I did was replace everything that said SQLITE_INNOCUOUS and SQLITE_DETERMINISTIC with SQLITE_IGNORE. And it worked, at least for this extension. Something like the following:
Before:
{
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
(void)pzErrMsg; /* Unused parameter */
rc = sqlite3_create_function(db, "uuid", 0, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
sqlite3UuidFunc, 0, 0);
if( rc==SQLITE_OK ){
rc = sqlite3_create_function(db, "uuid_str", 1,
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
0, sqlite3UuidStrFunc, 0, 0);
}
if( rc==SQLITE_OK ){
rc = sqlite3_create_function(db, "uuid_blob", 1,
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
0, sqlite3UuidBlobFunc, 0, 0);
}
return rc;
}
After:
{
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
(void)pzErrMsg; /* Unused parameter */
rc = sqlite3_create_function(db, "uuid", 0, SQLITE_UTF8 | SQLITE_IGNORE, 0,
sqlite3UuidFunc, 0, 0);
if (rc == SQLITE_OK)
{
rc = sqlite3_create_function(db, "uuid_str", 1,
SQLITE_UTF8 | SQLITE_IGNORE | SQLITE_IGNORE,
0, sqlite3UuidStrFunc, 0, 0);
}
if (rc == SQLITE_OK)
{
rc = sqlite3_create_function(db, "uuid_blob", 1,
SQLITE_UTF8 | SQLITE_IGNORE | SQLITE_IGNORE,
0, sqlite3UuidBlobFunc, 0, 0);
}
return rc;
}
Edit
I just had to declare this at the beginning of the code.
#define SQLITE_DETERMINISTIC 0x000000800
#define SQLITE_DIRECTONLY 0x000080000
#define SQLITE_SUBTYPE 0x000100000
#define SQLITE_INNOCUOUS 0x000200000
Related
This question already has answers here:
How do function pointers in C work?
(12 answers)
Closed last month.
I have a C program in which this pointer to function is defined. And i am getting compilation error, what am i doing wrong?
typedef long (*myfunc)(long, long, long, long);
void mytest() {
(*myfunc)(0, 0, 0, 0);
myfunc(0, 0, 0, 0);
}
output from gcc ./test.c
$ gcc ./test.c
./test.c: In function ‘mytest’:
./test.c:106:5: error: expected expression before ‘myfunc’
106 | (*myfunc)(0, 0, 0, 0);
| ^~~~~~
./test.c:107:10: error: expected identifier or ‘(’ before numeric constant
107 | myfunc(0, 0, 0, 0);
| ^
Edit:
compiler version
$ gcc --version
gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-3)
This is because myfunc is a type, and need to declare a variable first.
typedef long (*myfunc)(long, long, long, long);
void mytest() {
myfunc abc = 0;
abc(0, 0, 0, 0);
}
I was trying to compile some C code, which works fine on Linux with just one command.
./autogen.sh && ./configure && make
I need this to be compiled for windows, so I installed cygwin and all the dependencies that I could think of, and now I'm getting a compile error. (Error at make).
-cpu-miner.o `test -f 'cpu-miner.c' || echo './'`cpu-miner.c
cpu-miner.c: In function ‘miner_thread’:
cpu-miner.c:1056:139: error: ‘MAP_HUGETLB’ undeclared (first use in this function)
persistentctx = (struct cryptonight_ctx *)mmap(0, sizeof(struct cryptonight_ctx), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0);
^
cpu-miner.c:1056:139: note: each undeclared identifier is reported only once for each function it appears in
cpu-miner.c:1056:153: error: ‘MAP_POPULATE’ undeclared (first use in this function)
persistentctx = (struct cryptonight_ctx *)mmap(0, sizeof(struct cryptonight_ctx), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0);
^
cpu-miner.c:1058:88: error: ‘MADV_HUGEPAGE’ undeclared (first use in this function)
madvise(persistentctx, sizeof(struct cryptonight_ctx), MADV_RANDOM | MADV_WILLNEED | MADV_HUGEPAGE);
^
make[2]: *** [Makefile:563: minerd-cpu-miner.o] Error 1
The full code is over here:
https://github.com/wolf9466/cpuminer-multi
I installed Cygwin with gcc, ming-w64, libcurl, and openssl, as the project dependencies stated, but I'm stumped here.
(I did make changes to the code for optimization, but they're mathematical tweaks and they work fine on Linux, so I don't think that's the problem.)
Edit 1
It compiles now! I removed the hugepages thing and it compiled - but it's a Linux executable that has a .exe file name. It needs the cygwin dlls to run.
The "hugepage" feature is specific to Linux, and isn't available in Cygwin.
I recently started learning ZEROMQ and I am stuck somewhere. I tried to run the weather update examples(wuclient.c and wuserver.c) and I get the error below.
In file included from wuclient.c:5:0:
zhelpers.h: In function ‘s_sleep’:
zhelpers.h:133:5: warning: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration]
zhelpers.h: In function ‘s_console’:
zhelpers.h:158:5: warning: implicit declaration of function ‘time’ [-Wimplicit-function-declaration]
zhelpers.h:159:12: warning: implicit declaration of function ‘localtime’ [-Wimplicit-function-declaration]
zhelpers.h:159:26: warning: initialization makes pointer from integer without a cast [enabled by default]
zhelpers.h:161:5: warning: implicit declaration of function ‘strftime’ [-Wimplicit-function-declaration]
zhelpers.h:161:5: warning: incompatible implicit declaration of built-in function ‘strftime’ [enabled by default]
wuclient.c: At top level:
zhelpers.h:60:1: warning: ‘s_send’ defined but not used [-Wunused-function]
zhelpers.h:67:1: warning: ‘s_sendmore’ defined but not used [-Wunused-function]
zhelpers.h:75:1: warning: ‘s_dump’ defined but not used [-Wunused-function]
zhelpers.h:115:1: warning: ‘s_set_id’ defined but not used [-Wunused-function]
zhelpers.h:125:1: warning: ‘s_sleep’ defined but not used [-Wunused-function]
zhelpers.h:139:1: warning: ‘s_clock’ defined but not used [-Wunused-function]
zhelpers.h:156:1: warning: ‘s_console’ defined but not used [-Wunused-function]
The command I used to compile it is: gcc -Wall wuclient.c -o wuclient -L/usr/local/lib -lzmq
And this is the zhelpers.h code here https://github.com/imatix/zguide/blob/master/examples/C/zhelpers.h which is causing the error.
And it was included in this code below:
// Weather update client
// Connects SUB socket to tcp://localhost:5556
// Collects weather updates and finds avg temp in zipcode
#include "zhelpers.h"
int main (int argc, char *argv [])
{
// Socket to talk to server
printf ("Collecting updates from weather server...\n");
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
int rc = zmq_connect (subscriber, "tcp://localhost:5556");
assert (rc == 0);
// Subscribe to zipcode, default is NYC, 10001
char *filter = (argc > 1)? argv [1]: "10001 ";
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE,
filter, strlen (filter));
assert (rc == 0);
// Process 100 updates
int update_nbr;
long total_temp = 0;
for (update_nbr = 0; update_nbr < 100; update_nbr++) {
char *string = s_recv (subscriber);
int zipcode, temperature, relhumidity;
sscanf (string, "%d %d %d",
&zipcode, &temperature, &relhumidity);
total_temp += temperature;
free (string);
}
printf ("Average temperature for zipcode '%s' was %dF\n",
filter, (int) (total_temp / update_nbr));
zmq_close (subscriber);
zmq_ctx_destroy (context);
return 0;
}
I opened the "zhelpers.h" file and "time.h" was included. So I got confused on why this would happen. Am using Ubuntu 12.04 and please, I am neither an expert in C or ZEROMQ but this software looks like my realistic hope of scaling my thesis hurdle.
Thanks.
Note that these are just warnings and not errors. The compiler will still generate something but it might not work as intended.
The header file "zhelpers.h" includes <sys/time.h> and not <time.h> on Ubuntu. This is most probably incorrect. Remove the conditional in "zhelpers.h" and just include <time.h> on all platforms. This will remove half of the warnings.
The second half of the warnings are related to the fact that there are function definitions in "zhelpers.h". This is very poor coding style but the program should still work.
I'm trying to run a example from the "Using Graphviz as a library" in http://www.graphviz.org/Documentation.php.
#include <gvc.h>
int main(int argc, char **argv)
{
Agraph_t *g;
Agnode_t *n, *m;
Agedge_t *e;
Agsym_t *a;
GVC_t *gvc;
/* set up a graphviz context */
gvc = gvContext();
/* parse command line args - minimally argv[0] sets layout engine */
gvParseArgs(gvc, argc, argv);
/* Create a simple digraph */
g = agopen("g", Agdirected);
n = agnode(g, "n", 1);
m = agnode(g, "m", 1);
e = agedge(g, n, m, 0, 1);
/* Set an attribute - in this case one that affects the visible rendering */
agsafeset(n, "color", "red", "");
/* Compute a layout using layout engine from command line args */
gvLayoutJobs(gvc, g);
/* Write the graph according to -T and -o options */
gvRenderJobs(gvc, g);
/* Free layout data */
gvFreeLayout(gvc, g);
/* Free graph structures */
agclose(g);
/* close output file, free context, and return number of errors */
return (gvFreeContext(gvc));
}
I'm compiling and linking with : gcc -Wall pkg-config libgvc --cflags --libs *.c -o EXE -lgvc
and then I see this result:
graph.c: In function ‘main’:
graph.c:14:18: error: ‘Agdirected’ undeclared (first use in this function)
graph.c:14:18: note: each undeclared identifier is reported only once for each function it appears in
graph.c:15:2: error: too many arguments to function ‘agnode’
In file included from /usr/include/graphviz/types.h:717:0,
from /usr/include/graphviz/gvc.h:20,
from graph.c:1:
/usr/include/graphviz/graph.h:185:22: note: declared here
graph.c:16:2: error: too many arguments to function ‘agnode’
In file included from /usr/include/graphviz/types.h:717:0,
from /usr/include/graphviz/gvc.h:20,
from graph.c:1:
/usr/include/graphviz/graph.h:185:22: note: declared here
graph.c:17:2: error: too many arguments to function ‘agedge’
In file included from /usr/include/graphviz/types.h:717:0,
from /usr/include/graphviz/gvc.h:20,
from graph.c:1:
/usr/include/graphviz/graph.h:192:22: note: declared here
graph.c:7:11: warning: unused variable ‘a’ [-Wunused-variable]
graph.c:6:12: warning: variable ‘e’ set but not used [-Wunused-but-set-variable]
Could anyone help me understand what is going on? Why the compiler is complaining about those arguments in those functions?
Thank you!!!!
I saved your code as g.c, then issued this command line
gcc -Wall `pkg-config libgvc --cflags --libs` g.c -o EXE -lgvc
that yields
g.c: In function ‘main’:
g.c:14:5: error: too few arguments to function ‘agopen’
/usr/local/include/graphviz/cgraph.h:266:18: note: declared here
g.c:7:14: warning: unused variable ‘a’ [-Wunused-variable]
g.c:6:15: warning: variable ‘e’ set but not used [-Wunused-but-set-variable]
then I added the miss parameter
g = agopen("g", Agdirected, 0);
and the miss library
gcc -Wall `pkg-config libgvc --cflags --libs` g.c -lgvc -lcgraph
now the code compile and link with just 2 warnings:
g.c: In function ‘main’:
g.c:7:14: warning: unused variable ‘a’ [-Wunused-variable]
g.c:6:15: warning: variable ‘e’ set but not used [-Wunused-but-set-variable]
I think it works because I've built graphviz from source, then pkg-config is up-to-date...
The program still need some debug, running it i get:
./a.out
There is no layout engine support for "a.out"
Use one of: circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
Error: Layout was not done. Missing layout plugins?
The message is because by default the layout engine use the exe name (i.e. a.out, default of gcc compile-and-link) as layout string...
Doing an OS programming assignment using semaphores and POSIX threads. Here's my code:
#include <pthread.h>
#include <semaphore.h>
sem_t mutex, to_b, to_a;
int main()
{
// Initialize semaphores
sem_init(&mutex, 0, 1);
sem_init(&to_b, 0, 0);
sem_init(&to_a 0, 0);
}
Compiling with gcc main.c -lpthread I get:
main.c: In function 'main':
main.c:11:24: error: expected ')' before numeric constant
main.c:11:24: error: too few arguments to function 'sem_init'
/usr/include/semaphore.h:37:12: note: declared here
Any idea what could cause this? I'm definitely calling sem_init correctly.
There is a comma missing in
sem_init(&to_a 0, 0);
It should be
sem_init(&to_a, 0, 0);
sem_init(&to_a 0, 0);
^
You're just missing a comma.
So look at the error: main.c:11:24: error: too few arguments to function 'sem_init'
Line 11 has a problem, it has "too few arguments". You're making the same call on line 10 and 9 right? but no such error, so take a careful look, character for character between line 10 and line 11.
You'll see you missed a comma:
sem_init(&to_b, 0, 0);
sem_init(&to_a 0, 0); // see it's shorter?
Should be:
sem_init(&to_a, 0, 0);