Using pdfium.lib with GCC in a very simple program - gcc

I am trying to add pdfium.lib library in a small program in windows. The program is...
#include <fpdfview.h>
int main() {
FPDF_LIBRARY_CONFIG config;
config.version = 2;
config.m_pUserFontPaths = NULL;
config.m_pIsolate = NULL;
config.m_v8EmbedderSlot = 0;
FPDF_InitLibraryWithConfig(&config);
FPDF_DestroyLibrary();
return 0;
}
Pdfium.lib has build as complete lib and runs ok in Linux.(pdf_is_complete_lib = true).
When linking in GCC with the "-pg -s -Wl,--start-group pdfium.a -Wl,--end-group -lpthread" parameters works fine in Linux.
But in Windows10 with "-pg -s -Wl,--start-group pdfium.lib -Wl,--end-group -lpthread" parameters. Program say "main.cpp|7|undefined reference to `FPDF_InitLibrary'|, .... ||error: ld returned 1 exit status|
I am stack here in very simple program with main, because i am new to libs, so i need help.
I have also post the problem to google pdfium mailing list.
Thank you
Jim
But in windows i

Related

Linking guile to Rcpp

I am trying to link guile to an Rcpp file. It seems like things compile but there is an error when loading:
sourceCpp("test_2.cpp", rebuild = TRUE, showOutput = TRUE)
/usr/lib/R/bin/R CMD SHLIB --preclean -o 'sourceCpp_2.so' 'test_2.cpp'
g++-10 -I"/usr/share/R/include" -DNDEBUG -I"/home/matias/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include" -I"/home/matias/Documentos/Program/R/guile" -fpic -O3 -march=native -mtune=native -fPIC -pthread -I"/usr/include/guile/3.0" -c test_2.cpp -o test_2.o
g++-10 -shared -L/usr/lib/R/lib -lm -ldl -lgmpxx -lgmp -lmpfr -lmpc -lguile-3.0 -lgc -o sourceCpp_2.so test_2.o -L/usr/lib/R/lib -lR
Error in dyn.load("/tmp/Rtmpm2flY8/sourceCpp-x86_64-pc-linux-gnu-1.0.5/sourcecpp_29e2d33505085/sourceCpp_2.so") :
unable to load shared object '/tmp/Rtmpm2flY8/sourceCpp-x86_64-pc-linux-gnu-1.0.5/sourcecpp_29e2d33505085/sourceCpp_2.so':
/tmp/Rtmpm2flY8/sourceCpp-x86_64-pc-linux-gnu-1.0.5/sourcecpp_29e2d33505085/sourceCpp_2.so: undefined symbol: scm_init_guile
The linking works fine if I remove the Rcpp header and build directly with g++ instead.
My Makevars look like this:
CXX = g++-10
CXXFLAGS = -O3 -march=native -mtune=native -fPIC -pthread -I"/usr/include/guile/3.0"
CXXSTD = -std=c++11
LDFLAGS = -lm -ldl -lgmpxx -lgmp -lmpfr -lmpc -lguile-3.0 -lgc
The .cpp file:
#include <Rcpp.h>
#include <stdio.h>
#include <libguile.h>
using namespace Rcpp;
// [[Rcpp::export]]
int test_guile() {
SCM func, func2;
scm_init_guile();
scm_c_primitive_load("script.scm");
func = scm_variable_ref(scm_c_lookup("simple-func"));
func2 = scm_variable_ref(scm_c_lookup("quick-test"));
scm_call_0(func);
scm_call_0(func2);
return 0;
}
You are so, so close. You essentially solved this. I just took your file, made a small modification of making the script an argument and (as you didn't post script.scm) commented out the content-specific stuff. We still load it though:
#include <Rcpp.h>
#include <stdio.h>
#include <libguile.h>
using namespace Rcpp;
// [[Rcpp::export]]
int test_guile(std::string file) {
SCM func, func2;
scm_init_guile();
scm_c_primitive_load(file.c_str());
//func = scm_variable_ref(scm_c_lookup("simple-func"));
//func2 = scm_variable_ref(scm_c_lookup("quick-test"));
//scm_call_0(func);
//scm_call_0(func2);
return 0;
}
Similarly I just added a src/Makevars to the Rcpp.package.skeleton() created file. This is not good enough to ship as you need some minimal configure or alike logic to get these values from guile-config-3.0 or alike. But it passes the litmus test. C++11 is the default already under R 4.0.*, and the compiler is recent on my box anyway so we just have this (after removing a few GNU GMP and related parts we do not need):
PKG_CXXFLAGS = -I"/usr/include/guile/3.0"
PKG_LIBS = -lguile-3.0 -lgc
This now builds, installs, and runs just fine:
> file <- system.file("guile", "script.scm", package="RcppGuile")
> RcppGuile::test_guile(file)
[1] 0
>
For reference, I committed and pushed the entire example package here. If you provide a pointer to script.scm we can add that too.
Edit: A few seconds of googling leads to the script.scm you may have used so now we have a fully working example with a working embedded Guile interpreter:
> library(RcppGuile)
> test_guile(system.file("guile", "script.scm", package="RcppGuile"))
Script called, now I can change this
Adding another function, can modify without recompilation
Called this, without recompiling the C code
[1] 0
>

tensorflow c++ error: Unary VariantShapeFn for type_name: int already registered

i compliled tensorflow with bazel successfully and got libtensorflow_cc.so and libtensorflow_framework.so. Then i built a c++ binary with those share libraries successfully, but errors occurred when i run the binary, info is like:
F tensorflow/core/framework/variant_op_registry.cc:51] Check failed: existing == nullptr (0x24fc538 vs. nullptr)Unary VariantShapeFn for type_name: int already registered
c++ code:
#include "tensorflow/cc/client/client_session.h"
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor.h"
int main() {
using namespace tensorflow;
using namespace tensorflow::ops;
Scope root = Scope::NewRootScope();auto A = Const(root, { {3.f, 2.f}, {-1.f, 0.f} });
// // Vector b = [3 5
auto b = Const(root, { {3.f, 5.f} });
auto v = MatMul(root.WithOpName("v"), A, b, MatMul::TransposeB(true));
std::vector<Tensor> outputs;
ClientSession session(root);
// Run and fetch v
TF_CHECK_OK(session.Run({v}, &outputs));
// Expect outputs[0] == [19; -3]
LOG(INFO) << outputs[0].matrix<float>();
return 0;
}
i got my c++ binary using cmd:
g++ -std=c++11 test.cpp -o test -I./include -L./lib -L/home/work/chengjy/tools/protobuf/lib -I/home/work/chengjy/tools/tensorflow/eigen/eigen/eigen-eigen-fd6845384b86 -I/home/work/chengjy/tools/protobuf/include -ltensorflow_cc -ltensorflow_framework -lprotobuf -lpthread -ldl -O3 -Wall
did anyone have this problem before?
it seems that i fixed this problem by removing -ltensorflow_framework from the compile cmd.

Undefined function from static library

I am trying to build a static library using MinGW.
Everything was going fine until I tried to use the library and got an error saying that add_numbers is an undefined function.
Many other people have had this problem and sorted it out by moving their library to be linked after the source files were included, but that was how I had written my batch file anyway, so that was not of much help.
Here are my sources.
mylib.h
#ifndef MYLIB_H
#define MYLIB_H
int add_numbers(int a, int b, int c);
#endif
mylib.c
#include "mylib.h"
int add_numbers(int a, int b, int c)
{
return a+b+c;
}
I'm building my .a file with the following commands
gcc --std=c89 -c mylib.c -o mylib.o
ar rcs libmylib.a mylib.o
I've also tried with out specifying the standard.
There are no errors or warnings when running this command.
Next, my test program looks like this.
#include <stdio.h>
#include "mylib.h"
int main()
{
printf("The sum of 1, 2, and 3 is %d", add_numbers(1, 2, 3));
getchar();
return 0;
}
And lastly, we build the test with this command.
gcc mylibtest.c -L -lmylib -o test.exe
I've tried moving around those commands into many many different sequences, but always receiving the following error:
C:\Users\Aaron\AppData\Local\Temp\cc0ERpBi.o:mylibtest.c:(.text+0x26): undefined
reference to `add_numbers'
collect2.exe: error: ld returned 1 exit status
E:\my_first_static_library>
Any help would be very appreciated, I've read every tutorial I could find on the art of writing static libraries, as well as a good ten stackoverflow questions.
You are missing a dot after -L:
gcc mylibtest.c -L . -lmylib -o test.exe

Cannot use nana library

I try to use Nana library with Code::Block IDE. I made all settings like here
and add -std=C++11 flag and Boost include path but it's print next error on building:
nana/include/nana/paint/graphics.hpp|143|error: ‘unsigned int nana::paint::graphics::bidi_string(const nana::point&, const char*, std::size_t)’ cannot be overloaded|
nana/include/nana/paint/graphics.hpp|142|error:
with ‘unsigned int nana::paint::graphics::bidi_string(const nana::point&, const char_t*, std::size_t)’|
I only start study C++ 11 standart and Nana GUI library and cannot understand these bugs.
I faced the same problem.
To solve problem I look at how nana it self deal with this problem by compiling nana with make VERBOSE=1,
and take defines from it.
So to compiled example:
#include<nana/gui.hpp>
int main()
{
using namespace nana;
form fm;
drawing{fm}.draw([](paint::graphics& graph){
graph.string({10, 10}, L"Hello, world!", colors::red);
});
fm.events().click(API::exit);
fm.show();
exec();
}
from nana site(http://nanapro.org/en-us/) I use such command line:
g++ -DNANA_ENABLE_PNG -DNANA_LIBPNG -DNANA_LINUX -DNANA_UNICODE \
-DNANA_X11 -DPLATFORM_SPEC_HPP="<nana/detail/linux_X11/platform_spec.hpp>" \
-DSTD_CODECVT_NOT_SUPPORTED -std=c++11 -I nana/include/ \
test.cpp build/libnana.a -lX11 -lXft -lpthread -lpng

Display kernel error

I'm using GCC and the NVIDIA implementation of OpenCL, and online compilation instead of offline compilation.
I use this list to check which is the error I have. But nevertheless if I have an error inside my kernel the only information I have is an error value -48.
My question is: Is there a way to display the exact kernel compilation error?
If a semicolon is missing, or I have a wild pointer I would like to read so, instead of just a -48 error. Otherwise the development time is getting too slow.
I add also my Makefile:
CC=gcc
FILE=main
all:
$(CC) -c -Wall -I /usr/local/cuda/include/ $(FILE).c -o $(FILE).o
$(CC) $(FILE).o -o $(FILE) -L /usr/local/cuda/lib64/ -l OpenCL
clean:
$(RM) $(FILE) $(FILE).o
In C++, do something like:
int ErrorCode = 0;
cl_program P;
cl_device_id D;
size_t LogSize;
cl_build_status BuildStatus;
//Configure OpenCL
//Load Program Here
//Compile Program here
//Check the status of compilation
ErrorCode = clGetProgramBuildInfo(P, D, CL_PROGRAM_BUILD_STATUS, NULL, NULL, &BuildStatus);
if(BuildStatus == CL_BUILD_ERROR){
//Fetch Error
ErrorCode = clGetProgramBuildInfo(P, D, CL_PROGRAM_BUILD_LOG, NULL, NULL, &LogSize);
char Log = new Log[LogSize]; //Or use Malloc if in C
ErrorCode = clGetProgramBuildInfo(P, D, CL_PROGRAM_BUILD_LOG, LogSize, Log, NULL);
//Display Error Code here, close out OpenCL, try again, etc
}

Resources