FBExport - compile/use on Ubuntu - fbexport

TL;DR : How compile/use FBExport on Ubuntu / how export Firebird query result to csv file.
I would to like export query result from firebird database to csv file.
On Windows I do similary job using FBExport.
Unfortunetly I don't know use this tool on Ubuntu.
I downloaded pack from http://www.firebirdfaq.org/fbexport.php
When I try run ./fbexport i got error:
./fbexport: error while loading shared libraries: libfbclient.so.2:
cannot open shared object file: No such file or directory
Also I tried compile pack.
First I changed make file from:
###############################################################################
.SUFFIXES: .o .cpp
OBJECTS_FBE=fbexport/ParseArgs.o fbexport/FBExport.o fbexport/cli-main.o
OBJECTS_FBC=fbcopy/args.o fbcopy/fbcopy.o fbcopy/TableDependency.o fbcopy/main.o
# Compiler & linker flags
COMPILE_FLAGS=-O1 -DIBPP_LINUX -DIBPP_GCC -Iibpp
LINK_FLAGS=-pthread -lfbclient
#COMPILE_FLAGS=-O1 -DIBPP_WINDOWS -DIBPP_GCC -Iibpp
#LINK_FLAGS=
all: exe/fbcopy exe/fbexport
exe/fbexport: $(OBJECTS_FBE) ibpp/all_in_one.o
g++ $(LINK_FLAGS) ibpp/all_in_one.o $(OBJECTS_FBE) -oexe/fbexport
exe/fbcopy: $(OBJECTS_FBC) ibpp/all_in_one.o
g++ $(LINK_FLAGS) ibpp/all_in_one.o $(OBJECTS_FBC) -oexe/fbcopy
# Linux only
# FB2.0: g++ -pthread -lfbclient $(OBJECTS) -o$(EXENAME)
# FB1.5: g++ -lfbclient $(OBJECTS) -o$(EXENAME)
# FB1.0: g++ -lgds -lcrypt -lm $(OBJECTS) -o$(EXENAME)
install:
install exe/fbcopy /usr/bin/fbcopy
install exe/fbexport /usr/bin/fbexport
.cpp.o:
g++ -c $(COMPILE_FLAGS) -o $# $<
clean:
rm -f fbcopy/*.o
rm -f ibpp/all_in_one.o
rm -f exe/fbcopy*
rm -f fbexport/*.o
rm -f exe/fbexport*
#EOF
to:
###############################################################################
.SUFFIXES: .o .cpp
OBJECTS_FBE=fbexport/ParseArgs.o fbexport/FBExport.o fbexport/cli-main.o
# Compiler & linker flags
COMPILE_FLAGS=-O1 -DIBPP_LINUX -DIBPP_GCC -Iibpp
LINK_FLAGS=-pthread -lfbclient
#COMPILE_FLAGS=-O1 -DIBPP_WINDOWS -DIBPP_GCC -Iibpp
#LINK_FLAGS=
all: exe/fbexport
exe/fbexport: $(OBJECTS_FBE) ibpp/all_in_one.o
g++ $(LINK_FLAGS) ibpp/all_in_one.o $(OBJECTS_FBE) -oexe/fbexport
# Linux only
# FB2.0: g++ -pthread -lfbclient $(OBJECTS) -o$(EXENAME)
# FB1.5: g++ -lfbclient $(OBJECTS) -o$(EXENAME)
# FB1.0: g++ -lgds -lcrypt -lm $(OBJECTS) -o$(EXENAME)
install:
install exe/fbexport /usr/bin/fbexport
.cpp.o:
g++ -c $(COMPILE_FLAGS) -o $# $<
clean:
rm -f ibpp/all_in_one.o
rm -f fbexport/*.o
rm -f exe/fbexport*
#EOF
(because I like to compile only FBExport (excluding FBCopy))
After this change I tried run make in main folder.
Output:
user#apiserver:~/fbexport-1.90$ make
g++ -c -O1 -DIBPP_LINUX -DIBPP_GCC -Iibpp -o fbexport/ParseArgs.o fbexport/ParseArgs.cpp
g++ -c -O1 -DIBPP_LINUX -DIBPP_GCC -Iibpp -o fbexport/FBExport.o fbexport/FBExport.cpp
fbexport/FBExport.cpp: In member function ‘std::string FBExport::CreateHumanString(IBPP::Statement&, int)’:
fbexport/FBExport.cpp:318:29: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘int’ [-Wformat=]
318 | sprintf(str, "%ld", x);
| ~~^ ~
| | |
| | int
| long int
| %d
fbexport/FBExport.cpp:40:21: warning: format ‘%lli’ expects argument of type ‘long long int’, but argument 3 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
40 | #define INT64FORMAT "%lli"
| ^~~~~~
fbexport/FBExport.cpp:351:26: note: in expansion of macro ‘INT64FORMAT’
351 | sprintf(str, INT64FORMAT, int64val);
| ^~~~~~~~~~~
fbexport/FBExport.cpp:40:25: note: format string is defined here
40 | #define INT64FORMAT "%lli"
| ~~~^
| |
| long long int
| %li
fbexport/FBExport.cpp: In member function ‘bool FBExport::CreateString(IBPP::Statement&, int, std::string&)’:
fbexport/FBExport.cpp:429:29: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘int’ [-Wformat=]
429 | sprintf(str, "%ld", x);
| ~~^ ~
| | |
| | int
| long int
| %d
fbexport/FBExport.cpp:435:29: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘int’ [-Wformat=]
435 | sprintf(str, "%ld", d.GetDate());
| ~~^ ~~~~~~~~~~~
| | |
| long int int
| %d
fbexport/FBExport.cpp:440:29: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘int’ [-Wformat=]
440 | sprintf(str, "%ld", t.GetTime());
| ~~^ ~~~~~~~~~~~
| | |
| long int int
| %d
fbexport/FBExport.cpp:40:21: warning: format ‘%lli’ expects argument of type ‘long long int’, but argument 3 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
40 | #define INT64FORMAT "%lli"
| ^~~~~~
fbexport/FBExport.cpp:462:26: note: in expansion of macro ‘INT64FORMAT’
462 | sprintf(str, INT64FORMAT, int64val);
| ^~~~~~~~~~~
fbexport/FBExport.cpp:40:25: note: format string is defined here
40 | #define INT64FORMAT "%lli"
| ~~~^
| |
| long long int
| %li
fbexport/FBExport.cpp: In member function ‘int FBExport::Export(IBPP::Statement&, FILE*)’:
fbexport/FBExport.cpp:487:18: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
487 | register int fc = st->Columns();
| ^~
fbexport/FBExport.cpp:491:23: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
491 | for (register int i=1; i<=fc; i++)
| ^
fbexport/FBExport.cpp:505:27: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
505 | for (register int i=1; i<=fc; i++) // ... export all fields to file.
| ^
fbexport/FBExport.cpp: In member function ‘int FBExport::ExportHuman(IBPP::Statement&, FILE*)’:
fbexport/FBExport.cpp:829:18: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
829 | register int fc = st->Columns();
| ^~
fbexport/FBExport.cpp:835:27: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
835 | for (register int i=1; i<=fc; i++) // output CSV header.
| ^
fbexport/FBExport.cpp:847:27: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
847 | for (register int i=1; i<=fc; i++) // ... export all fields to file.
| ^
fbexport/FBExport.cpp:860:27: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
860 | for (register int i=1; i<=fc; i++) // output CSV header.
| ^
fbexport/FBExport.cpp:875:27: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
875 | for (register int i=1; i<=fc; i++) // ... export all fields to file.
| ^
fbexport/FBExport.cpp: In function ‘int statement_length(FILE*)’:
fbexport/FBExport.cpp:1335:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
1335 | register int c = 0, tmp = 0;
| ^
fbexport/FBExport.cpp:1335:31: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
1335 | register int c = 0, tmp = 0;
| ^~~
fbexport/FBExport.cpp:1336:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
1336 | register int l = 0;
| ^
fbexport/FBExport.cpp: In function ‘char* read_statement(char*, int, FILE*)’:
fbexport/FBExport.cpp:1376:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
1376 | register int c = 0, tmp = 0;
| ^
fbexport/FBExport.cpp:1376:31: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
1376 | register int c = 0, tmp = 0;
| ^~~
fbexport/FBExport.cpp:1377:25: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
1377 | register char *P;
| ^
fbexport/FBExport.cpp: In member function ‘std::string FBExport::CreateHumanString(IBPP::Statement&, int)’:
fbexport/FBExport.cpp:339:17: warning: ignoring return value of ‘char* gcvt(double, int, char*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
339 | gcvt(fval, 19, str);
| ~~~~^~~~~~~~~~~~~~~
fbexport/FBExport.cpp:345:17: warning: ignoring return value of ‘char* gcvt(double, int, char*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
345 | gcvt(dval, 19, str);
| ~~~~^~~~~~~~~~~~~~~
fbexport/FBExport.cpp: In member function ‘bool FBExport::CreateString(IBPP::Statement&, int, std::string&)’:
fbexport/FBExport.cpp:452:17: warning: ignoring return value of ‘char* gcvt(double, int, char*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
452 | gcvt(fval, 19, str);
| ~~~~^~~~~~~~~~~~~~~
fbexport/FBExport.cpp:457:17: warning: ignoring return value of ‘char* gcvt(double, int, char*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
457 | gcvt(dval, 19, str);
| ~~~~^~~~~~~~~~~~~~~
fbexport/FBExport.cpp: In member function ‘int FBExport::Import(IBPP::Statement&, FILE*)’:
fbexport/FBExport.cpp:706:26: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
706 | fread(buff, size, 1, fp);
| ~~~~~^~~~~~~~~~~~~~~~~~~
fbexport/FBExport.cpp: In member function ‘int FBExport::Init(Arguments*)’:
fbexport/FBExport.cpp:1211:41: warning: ‘__builtin___sprintf_chk’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
1211 | sprintf(num, "%d", i+1);
| ^
In file included from /usr/include/stdio.h:888,
from /usr/include/c++/11/cstdio:42,
from /usr/include/c++/11/ext/string_conversions.h:43,
from /usr/include/c++/11/bits/basic_string.h:6606,
from /usr/include/c++/11/string:55,
from ibpp/ibpp.h:91,
from fbexport/FBExport.cpp:44:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:38:34: note: ‘__builtin___sprintf_chk’ output between 2 and 11 bytes into a destination of size 10
38 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~
g++ -c -O1 -DIBPP_LINUX -DIBPP_GCC -Iibpp -o fbexport/cli-main.o fbexport/cli-main.cpp
g++ -c -O1 -DIBPP_LINUX -DIBPP_GCC -Iibpp -o ibpp/all_in_one.o ibpp/all_in_one.cpp
g++ -pthread -lfbclient ibpp/all_in_one.o fbexport/ParseArgs.o fbexport/FBExport.o fbexport/cli-main.o -oexe/fbexport
What can I do in this case?
Regards
Tomasz

Related

Intel realsense R200: Errors when running 'make'

I am trying to install the libraries necessaries to run Intel Realsense R200 in my Linux Mint distribution. For that I follow the steps defined under this link: https://github.com/IntelRealSense/librealsense/blob/v1.12.1/doc/installation.md. Everything works fine till I execute on step 5 the command make && sudo make install. Then I get the output showed below. Does anyone know how to solve this so that I can finish the installation? Thanks in advance.
In file included from /home/xxx/Software/librealsense/src/archive.h:8,
from /home/xxx/Software/librealsense/src/archive.cpp:2:
/home/xxx/Software/librealsense/src/types.h:577:14: error: ‘function’ in namespace ‘std’ does not name a template type
577 | std::function<void()> continuation;
| ^~~~~~~~
In file included from /home/xxx/Software/librealsense/src/archive.h:8,
from /home/xxx/Software/librealsense/src/archive.cpp:2:
/home/xxx/Software/librealsense/src/types.h:25:1: note: ‘std::function’ is defined in header ‘<functional>’; did you forget to ‘#include <functional>’?
24 | #include <algorithm>
+++ |+#include <functional>
25 |
In file included from /home/xxx/Software/librealsense/src/archive.h:8,
from /home/xxx/Software/librealsense/src/archive.cpp:2:
/home/xxx/Software/librealsense/src/types.h:585:50: error: expected ‘)’ before ‘<’ token
585 | explicit frame_continuation(std::function<void()> continuation, const void* protected_data) : continuation(continuation), protected_data(protected_data) {}
| ~ ^
| )
/home/xxx/Software/librealsense/src/types.h: In constructor ‘rsimpl::frame_continuation::frame_continuation()’:
/home/xxx/Software/librealsense/src/types.h:583:32: error: class ‘rsimpl::frame_continuation’ does not have any field named ‘continuation’
583 | frame_continuation() : continuation([]() {}) {}
| ^~~~~~~~~~~~
/home/xxx/Software/librealsense/src/types.h: In constructor ‘rsimpl::frame_continuation::frame_continuation(rsimpl::frame_continuation&&)’:
/home/xxx/Software/librealsense/src/types.h:588:59: error: class ‘rsimpl::frame_continuation’ does not have any field named ‘continuation’
588 | frame_continuation(frame_continuation && other) : continuation(std::move(other.continuation)), protected_data(other.protected_data)
| ^~~~~~~~~~~~
/home/xxx/Software/librealsense/src/types.h:588:88: error: ‘class rsimpl::frame_continuation’ has no member named ‘continuation’; did you mean ‘frame_continuation’?
588 | frame_continuation(frame_continuation && other) : continuation(std::move(other.continuation)), protected_data(other.protected_data)
| ^~~~~~~~~~~~
| frame_continuation
/home/xxx/Software/librealsense/src/types.h:590:19: error: ‘class rsimpl::frame_continuation’ has no member named ‘continuation’; did you mean ‘frame_continuation’?
590 | other.continuation = []() {};
| ^~~~~~~~~~~~
| frame_continuation
/home/xxx/Software/librealsense/src/types.h: In member function ‘void rsimpl::frame_continuation::operator()()’:
/home/xxx/Software/librealsense/src/types.h:596:13: error: ‘continuation’ was not declared in this scope; did you mean ‘frame_continuation’?
596 | continuation();
| ^~~~~~~~~~~~
| frame_continuation
/home/xxx/Software/librealsense/src/types.h: In member function ‘void rsimpl::frame_continuation::reset()’:
/home/xxx/Software/librealsense/src/types.h:604:13: error: ‘continuation’ was not declared in this scope; did you mean ‘frame_continuation’?
604 | continuation = [](){};
| ^~~~~~~~~~~~
| frame_continuation
/home/xxx/Software/librealsense/src/types.h: In member function ‘rsimpl::frame_continuation& rsimpl::frame_continuation::operator=(rsimpl::frame_continuation&&)’:
/home/xxx/Software/librealsense/src/types.h:611:13: error: ‘continuation’ was not declared in this scope; did you mean ‘frame_continuation’?
611 | continuation();
| ^~~~~~~~~~~~
| frame_continuation
/home/xxx/Software/librealsense/src/types.h:613:34: error: ‘class rsimpl::frame_continuation’ has no member named ‘continuation’; did you mean ‘frame_continuation’?
613 | continuation = other.continuation;
| ^~~~~~~~~~~~
| frame_continuation
/home/xxx/Software/librealsense/src/types.h:614:19: error: ‘class rsimpl::frame_continuation’ has no member named ‘continuation’; did you mean ‘frame_continuation’?
614 | other.continuation = []() {};
| ^~~~~~~~~~~~
| frame_continuation
/home/xxx/Software/librealsense/src/types.h: In destructor ‘rsimpl::frame_continuation::~frame_continuation()’:
/home/xxx/Software/librealsense/src/types.h:621:13: error: ‘continuation’ was not declared in this scope; did you mean ‘frame_continuation’?
621 | continuation();
| ^~~~~~~~~~~~
| frame_continuation
/home/xxx/Software/librealsense/src/types.h: At global scope:
/home/xxx/Software/librealsense/src/types.h:630:44: error: expected ‘)’ before ‘<’ token
630 | calibration_validator(std::function<bool(rs_stream, rs_stream)> extrinsic_validator,
| ~ ^
| )
/home/xxx/Software/librealsense/src/types.h:638:14: error: ‘function’ in namespace ‘std’ does not name a template type
638 | std::function<bool(rs_stream from_stream, rs_stream to_stream)> extrinsic_validator;
| ^~~~~~~~
/home/xxx/Software/librealsense/src/types.h:638:9: note: ‘std::function’ is defined in header ‘<functional>’; did you forget to ‘#include <functional>’?
638 | std::function<bool(rs_stream from_stream, rs_stream to_stream)> extrinsic_validator;
| ^~~
/home/xxx/Software/librealsense/src/types.h:639:14: error: ‘function’ in namespace ‘std’ does not name a template type
639 | std::function<bool(rs_stream stream)> intrinsic_validator;
| ^~~~~~~~
/home/xxx/Software/librealsense/src/types.h:639:9: note: ‘std::function’ is defined in header ‘<functional>’; did you forget to ‘#include <functional>’?
639 | std::function<bool(rs_stream stream)> intrinsic_validator;
| ^~~
make[2]: *** [CMakeFiles/realsense.dir/build.make:63: CMakeFiles/realsense.dir/src/archive.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:189: CMakeFiles/realsense.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

Prevent CUDA-enabled MPI from checking for CUDA devices

The OpenMPI 4.0.5 on our cluster is built with CUDA support, but I want to benchmark pnetcdf without needing CUDA for that. Since I want to do a number of test runs that I can start on like 1/4th of a node and my tests won't make use of the GPUs I wanted to ask if there is a way to suppress the MPI check for CUDA devices. Because when I simply obtain a SLURM allocation without GPUs, I get lots of errors from that alone.
These errors come from hwloc, and can be suppressed with HWLOC_HIDE_ERRORS=1 but I'd like to know if there is a more specific method.
Steps to reproduce:
frontend$ salloc -n 16 -t 8:00:00 -A k20200
node$ exec bash -l
node$ module load gcc openmpi
node$ mpicc -o /tmp/hello ~/usr/src/helloworld_mpi.c
node$ srun -n 1 /tmp/hello
CUDA: Failed to get number of devices with cudaGetDeviceCount(): no CUDA-capable device is detected
Hello world!, I'm rank 0 of 1!
node$ HWLOC_HIDE_ERRORS=1 srun -n 1 /tmp/hello
Hello world!, I'm rank 0 of 1!
node$ logout
The example code used above is the following but any program without CUDA use is equally useful in this exercise
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#define xmpi(rc) \
do { \
int err = (rc); \
if (err != MPI_SUCCESS) { \
char msg[MPI_MAX_ERROR_STRING + 1]; \
int msg_len; \
\
if (MPI_Error_string(err, msg, &msg_len) \
== MPI_SUCCESS){ \
msg[msg_len] = '\0'; \
\
fprintf(stderr, \
"Problem in MPI call: %d = %s\n", \
err, msg); \
MPI_Abort(MPI_COMM_WORLD, 1); \
} \
} \
} while (0)
int
main(int argc, char *argv[])
{
xmpi(MPI_Init(&argc, &argv));
int rank, size;
xmpi(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
xmpi(MPI_Comm_size(MPI_COMM_WORLD, &size));
printf("Hello world!, I'm rank %d of %d!\n", rank, size);
xmpi(MPI_Finalize());
return EXIT_SUCCESS;
}

Cmake undefined reference to function hello() [duplicate]

I have a test file (just for the link test) where I overload the new/delete operators with my own malloc/free library called libxmalloc.a. But I keep getting "undefined reference to" error as following when linking the static library, even I change the order of test.o and -lxmalloc. But everything works well with other C programs linking this library. I'm so confused with this issue and appreciate any clue.
Error Msg:
g++ -m64 -O3 -I/usr/include/ethos -I/usr/include/nacl/x86_64 -c -o test.o test.cpp
g++ -m64 -O3 -L. -o demo test.o -lxmalloc
test.o: In function `operator new(unsigned long)':
test.cpp:(.text+0x1): undefined reference to `malloc(unsigned long)'
test.o: In function `operator delete(void*)':
test.cpp:(.text+0x11): undefined reference to `free(void*)'
test.o: In function `operator new[](unsigned long)':
test.cpp:(.text+0x21): undefined reference to `malloc(unsigned long)'
test.o: In function `operator delete[](void*)':
test.cpp:(.text+0x31): undefined reference to `free(void*)'
test.o: In function `main':
test.cpp:(.text.startup+0xc): undefined reference to `malloc(unsigned long)'
test.cpp:(.text.startup+0x19): undefined reference to `malloc(unsigned long)'
test.cpp:(.text.startup+0x24): undefined reference to `free(void*)'
test.cpp:(.text.startup+0x31): undefined reference to `free(void*)'
collect2: ld returned 1 exit status
make: *** [demo] Error 1
My test.cpp file:
#include <dual/xalloc.h>
#include <dual/xmalloc.h>
void*
operator new (size_t sz)
{
return malloc(sz);
}
void
operator delete (void *ptr)
{
free(ptr);
}
void*
operator new[] (size_t sz)
{
return malloc(sz);
}
void
operator delete[] (void *ptr)
{
free(ptr);
}
int
main(void)
{
int *iP = new int;
int *aP = new int[3];
delete iP;
delete[] aP;
return 0;
}
My Makefile:
CFLAGS += -m64 -O3 -I/usr/include/ethos -I/usr/include/nacl/x86_64
CXXFLAGS += -m64 -O3
LIBDIR += -L.
LIBS += -lxmalloc
all: demo
demo: test.o
$(CXX) $(CXXFLAGS) $(LIBDIR) -o demo test.o $(LIBS)
test.o: test.cpp
$(CXX) $(CFLAGS) -c -o $# $<
clean:
- rm -f *.o demo
But everything works well with other C programs linking this library.
Did you notice that C and C++ compilation create different symbol names on object file level? It's called 'name mangling'.
The (C++) linker would show undefined references as demangled symbols in the error message, which might confuse you. If you inspect your test.o file with nm -u you'll see that the referenced symbol names don't match with those provided in your library.
If you want to use functions linked in as externals that were compiled using the plain C compiler, you'll need their function declarations enclosed in an extern "C" {} block which suppresses C++ name mangling for everything declared or defined inside, e.g.:
extern "C"
{
#include <dual/xalloc.h>
#include <dual/xmalloc.h>
}
Even better, you might wrap your function declarations in your header files like this:
#if defined (__cplusplus)
extern "C" {
#endif
/*
* Put plain C function declarations here ...
*/
#if defined (__cplusplus)
}
#endif

How to manage module dependencies in jq

Since version 1.5 the jq data processing language has a library module system. A module consists of optional metadata and a set of functions. For instance
module { name: "util", version: "1.0.0" };
def digitsum: tostring|split("")|map(tonumber)|add;
stored as file util.jq can be used like this:
$ echo '789' | jq -L. 'include "util"; digitsum'
24
Modules can use other modules and the dependencies are tracked by the modulemeta directive but how to express and check for a minimum version of a module number? For instance:
module {
name: "math",
version: "0.1.0",
};
include "util"; # TODO: require at least version 1.0.0!
def digitroot:
(.|digitsum) as $sum |
if $sum<10 then $sum else $sum|digitroot end;
The support for modules in jq is currently (June 2019) still very minimal, though on github there is a module management system for jq: https://github.com/joelpurra/jqnpm
Without using such an external module management system, what can be done in jq itself? Extending the given example, the following illustrates one approach to supporting version requirements. Notice the additional key named dependencies in the metadata of the math module. (Currently, this key cannot be named deps as jq overwrites it.)
Files
dependencies.jq
# Recursively check specified version constraints
module { name: "dependencies", version: "0.0.2" };
# parents of a module as defined by its .deps
def parents:
. as $in
| if type == "array" then map(parents) | add
else modulemeta | .deps | map(.relpath)
end ;
# ancestors of a single module or an array of modules.
# The array of "ancestors" of a module includes itself.
def ancestors:
# input and $visited should be arrays of strings
def ancestors($visited):
. as $in
| ($in - $visited) as $new
| if $new == [] then $visited
else $new | parents | ancestors($visited + $new | unique)
end;
if type == "array" then . else [.] end
| ancestors([]) ;
def versionsort:
def parse:
sub("(?<a>(alpha|beta|gamma))"; "\(.a).")
| [splits("[-.]")]
| map(tonumber? // .) ;
sort_by(parse);
# Input: a module name
# Emit empty if the constraints for the given module are satisfied, otherwise raise an error
def dependencies($version):
def le($y): (. == $y) or ([.,$y] | . == versionsort);
modulemeta
| .version as $mv
| if (($mv == null) or ($version | le($mv))) then empty
else ("module \(.name) dependencies version \($version) vs \($mv)" | error)
end ;
# Input: a module name or array of module names
# Check the module-version dependencies in .dependencies, proceeding up the chain as defined by .deps
def dependencies:
def check:
modulemeta
| select(has("dependencies"))
| all( .dependencies | to_entries[];
.key as $m | .value as $v | ($m | dependencies($v) ))
| empty;
ancestors[] | check;
util.jq
module { name: "util", version: "1.0.0" };
def digitsum: tostring|split("")|map(tonumber)|add;
math.jq
module {
name: "math",
version: "0.1.0",
dependencies: {"util": "1.0.0"} };
include "util" ;
def digitroot:
digitsum as $sum
| if $sum<10 then $sum
else $sum|digitroot
end;
Invocation
jq -n -L . '
include "dependencies";
include "math";
"math" | dependencies,
(123|digitroot) '

How to Compile Programs Built With Yacc and Lex?

My Yacc source is in pos.yacc and my Lex source is in pos1.lex, as shown.
pos1.lex
%{
#include "y.tab.h"
int yylval;
%}
DIGIT [0-9]+
%%
{DIGIT} {yylval=atoi(yytext);return DIGIT;}
[\n ] {}
. {return *yytext;}
%%
pos.yacc
%token DIGIT
%%
s:e {printf("%d\n",$1);}
e:DIGIT {$$=$1;}
|e e "+" {$$=$1+$2;}
|e e "*" {$$=$1*$2;}
|e e "-" {$$=$1-$2;}
|e e "/" {$$=$1/$2;}
;
%%
main() {
yyparse();
}
yyerror() {
printf("Error");
}
Compilation errors
While compiling I am getting errors like:
malathy#malathy:~$ cc lex.yy.c y.tab.c -ly -ll
pos.y: In function ‘yyerror’:
pos.y:16: warning: incompatible implicit declaration of built-in function ‘printf’
pos.y: In function ‘yyparse’:
pos.y:4: warning: incompatible implicit declaration of built-in function ‘printf’
What causes those errors?
How am I supposed to compile Lex and Yacc source code?
printf() is defined in stdio.h so just include it above y.tab.h in pos1.lex:
%{
#include <stdio.h>
/* Add ^^^^^^^^^^^ this line */
#include "y.tab.h"
int yylval;
%}
DIGIT [0-9]+
%%
{DIGIT} {yylval=atoi(yytext);return DIGIT;}
[\n ] {}
. {return *yytext;}
%%
You have the direct answer to your question from trojanfoe - you need to include <stdio.h> to declare the function printf(). This is true in any source code presented to the C compiler.
However, you should also note that the conventional suffix for Yacc source is .y (rather than .yacc), and for Lex source is .l (rather than .lex). In particular, using those sufffixes means that make will know what to do with your source, rather than having to code the compilation rules by hand.
Given files lex.l and yacc.y, make compiles them to object code using:
$ make lex.o yacc.o
rm -f lex.c
lex -t lex.l > lex.c
cc -O -std=c99 -Wall -Wextra -c -o lex.o lex.c
yacc yacc.y
mv -f y.tab.c yacc.c
cc -O -std=c99 -Wall -Wextra -c -o yacc.o yacc.c
rm lex.c yacc.c
$
This is in a directory with a makefile that sets CFLAGS = -O -std=c99 -Wall -Wextra. (This was on MacOS X 10.6.6.) You will sometimes see other similar rules used; in particular, lex generates a file lex.yy.c by default (at least on MacOS X), and you'll often see a rule such as:
lex lex.l
mv lex.yy.c lex.c
cc -O -std=c99 -Wall -Wextra -c -o lex.o lex.c
Or even:
lex lex.l
cc -O -std=c99 -Wall -Wextra -c -o lex.o lex.yy.c
The alternatives are legion; use make and it gets it right.
Include header file stdio.h
for compilation
open terminal locate both files and type
lex pos1.l
yacc pos.y
cc lex.yy.c y.tab.h -ll
./a.out
You can follow these steps.
you just need to save in file
pos1.l and pos.y
I hope it will work