Cygwin cmake problems on windows - c++

I am trying to cmake on windows computer. I encountered following error in CMakeError.log
Run Build Command(s):/usr/bin/ninja.exe cmTC_ff288 && [1/2] Building C object CMakeFiles/cmTC_ff288.dir/CheckSymbolExists.c.o
FAILED: CMakeFiles/cmTC_ff288.dir/CheckSymbolExists.c.o
/usr/bin/cc -fdiagnostics-color=always -Wextra -Wall -Wno-expansion-to-defined -Wno-psabi -Wno-misleading-indentation -Wno-maybe-uninitialized -Wwrite-strings -Wundef -Wpointer-arith -Wmissing-format-attribute -Wformat-security -Wcast-align -Wno-tautological-compare -fno-strict-aliasing -fno-exceptions -o CMakeFiles/cmTC_ff288.dir/CheckSymbolExists.c.o -c CheckSymbolExists.c
CheckSymbolExists.c:2:10: fatal error: pthread_np.h: No such file or directory
2 | #include <pthread_np.h>
| ^~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
File /cygdrive/f/gtkwebkit/webkitgtk-2.34.1/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread_np.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef pthread_main_np
return ((int*)(&pthread_main_np))[argc];
#else
(void)argc;
return 0;
#endif
}
Does anyone know how to fix it? Since it is a temp file I could not modify this line of include

Related

How to properly call C++ library function in Java Activity

I am using GitHub in-paint library https://github.com/cheind/inpaint in android studio
and trying to call jni fuction of inpainter in main activity but it is not resolving or getting recognized.
C++ is new to me so i am having issue.
in criminisi_inpainter.cpp file
there is this function
void inpaintCriminisi(
cv::InputArray image,
cv::InputArray targetMask,
cv::InputArray sourceMask,
int patchSize)
{
CriminisiInpainter ci;
ci.setSourceImage(image.getMat());
ci.setSourceMask(sourceMask.getMat());
ci.setTargetMask(targetMask.getMat());
ci.setPatchSize(patchSize);
ci.initialize();
while (ci.hasMoreSteps()) {
ci.step();
}
ci.image().copyTo(image.getMat());
}
this native function i have to call in main activity
public native void inpaintCriminisi( ? , ? ,? , int z);
The issue is i do not understand what parameters would be provided here in main activity (JAVA)
In nativelib.cpp i am exporting jnicall function i give object parameters which is not exact parameters that should be defined.
extern "C"
JNIEXPORT void JNICALL
Java_com_example_raweeda_applicationc_MainActivity_inpaintCriminisi(JNIEnv *env, jobject instance,
jobject a, jobject b, jobject c,
jint xl) {
// TODO
inpaintCriminisi(x,y,z,xl);
parameters are not object it just an example
}
this is the error i am recieving
Build command failed.
Error while executing process C:\Users\abc\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\2019_android\ApplicationC\app\.externalNativeBuild\cmake\debug\x86 --target native-lib}
[1/3] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/3] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/criminisi_inpainter.cpp.o
FAILED: C:\Users\abc\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android19 --gcc-toolchain=C:/Users/abc/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 -Dnative_lib_EXPORTS -ID:/opencv-sdk/OpenCV-android-sdk/sdk/native/jni/include --sysroot C:/Users/abc/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -std=c++11 -frtti -fexceptions -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -MF CMakeFiles\native-lib.dir\src\main\cpp\native-lib.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -c D:\2019_android\ApplicationC\app\src\main\cpp\native-lib.cpp
D:\2019_android\ApplicationC\app\src\main\cpp\native-lib.cpp:13:5: warning: declaration does not declare anything [-Wmissing-declarations]
cv::InputArray ;
^~~~~~~~~~~~~~
D:\2019_android\ApplicationC\app\src\main\cpp\native-lib.cpp:23:39: error: expected '(' for function-style cast or type construction
inpaintCriminisi( cv::InputArray image,
~~~~~~~~~~~~~~ ^
D:\2019_android\ApplicationC\app\src\main\cpp\native-lib.cpp:24:28: error: expected '(' for function-style cast or type construction
cv::InputArray targetMask,
~~~~~~~~~~~~~~ ^
D:\2019_android\ApplicationC\app\src\main\cpp\native-lib.cpp:25:28: error: expected '(' for function-style cast or type construction
cv::InputArray sourceMask,
~~~~~~~~~~~~~~ ^
D:\2019_android\ApplicationC\app\src\main\cpp\native-lib.cpp:26:17: error: expected '(' for function-style cast or type construction
int patchSize);
~~~ ^
1 warning and 4 errors generated.
FAILED: C:\Users\abc\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android19 --gcc-toolchain=C:/Users/abc/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 -Dnative_lib_EXPORTS -ID:/opencv-sdk/OpenCV-android-sdk/sdk/native/jni/include --sysroot C:/Users/abc/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -std=c++11 -frtti -fexceptions -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/src/main/cpp/criminisi_inpainter.cpp.o -MF CMakeFiles\native-lib.dir\src\main\cpp\criminisi_inpainter.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/criminisi_inpainter.cpp.o -c D:\2019_android\ApplicationC\app\src\main\cpp\criminisi_inpainter.cpp
In file included from D:\2019_android\ApplicationC\app\src\main\cpp\criminisi_inpainter.cpp:7:
D:\2019_android\ApplicationC\app\src\main\cpp/timer.h:83:1: error: extraneous closing brace ('}')
}
^
D:\2019_android\ApplicationC\app\src\main\cpp\criminisi_inpainter.cpp:10:10: fatal error: 'opencv' file not found
#include "opencv"
^~~~~~~~
2 errors generated.
ninja: build stopped: subcommand failed.
because in nativelib.cpp

c++ Pin shared library undefined symbol

I am using the Intel Pin tool to generate a shared object file from a C source file and a C++ pintool. I have used the following g++ commands to generate my shared object file. Apologies in advance as the commands are very big due to the Pin libraries and options.
g++ -DBIGARRAY_MULTIPLIER=1 -Wall -Werror -Wno-unknown-pragmas -D__PIN__=1 -DPIN_CRT=1 -fno-stack-protector -fno-exceptions -funwind-tables -fasynchronous-unwind-tables -fno-rtti -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_LINUX -fabi-version=2 -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/source/include/pin -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/source/include/pin/gen -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/stlport/include -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/libstdc++/include -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/crt/include -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/crt/include/arch-x86_64 -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/crt/include/kernel/uapi -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/crt/include/kernel/uapi/asm-x86 -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/components/include -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/xed-intel64/include/xed -Iinc -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/source/tools/InstLib -O0 -c -o obj-intel64/testcpp.o testcpp.cpp
g++ -DBIGARRAY_MULTIPLIER=1 -Wall -Werror -Wno-unknown-pragmas -D__PIN__=1 -DPIN_CRT=1 -fno-stack-protector -fno-exceptions -funwind-tables -fasynchronous-unwind-tables -fno-rtti -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_LINUX -fabi-version=2 -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/source/include/pin -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/source/include/pin/gen -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/stlport/include -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/libstdc++/include -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/crt/include -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/crt/include/arch-x86_64 -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/crt/include/kernel/uapi -isystem /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/crt/include/kernel/uapi/asm-x86 -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/components/include -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/xed-intel64/include/xed -Iinc -I/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/source/tools/InstLib -O0 -c -o obj-intel64/test.o test.c
g++ -shared -Wl,-z,defs -Wl,--hash-style=sysv /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/intel64/runtime/pincrt/crtbeginS.o -Wl,-Bsymbolic -Wl,--version-script=/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/source/include/pin/pintool.ver -fabi-version=2 obj-intel64/testcpp.so -o obj-intel64/testcpp.o obj-intel64/test.o -L/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/intel64/runtime/pincrt -L/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/intel64/lib -L/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/intel64/lib-ext -L/home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/extras/xed-intel64/lib -lpin -lxed /home/rohit/github_repos/uli/src/pin/pin-3.2-81205-gcc-linux/intel64/runtime/pincrt/crtendS.o -lpin3dwarf -ldl-dynamic -nostdlib -lstlport-dynamic -lm-dynamic -lc-dynamic -lunwind-dynamic
testcpp.cpp is my C++ pintool and test.c is my C source file. The folder inc contains the header file test.h which is included in both of them.
This is my C++ file -
#include "pin.H"
#include <iostream>
#include <fstream>
extern "C" {
#include <test.h>
}
using namespace std;
KNOB<string> KnobOutputFile(KNOB_MODE_WRITEONCE, "pintool", "o", "test.out","This pin tool simulates ULI");
FILE * op;
VOID Instruction(INS ins, void *v) {
}
VOID Fini(INT32 code, VOID *v) {
fprintf(op,"Ended from c++\n");
fprintf(op,"%d\n",cfunc(11,2));
fclose(op);
}
INT32 Usage() {
PIN_ERROR("This Pintool failed\n" + KNOB_BASE::StringKnobSummary() + "\n");
return -1;
}
int main(int argc, char *argv[]) {
if (PIN_Init(argc, argv))
return Usage();
op = fopen("test.out", "w");
PIN_InitSymbols();
INS_AddInstrumentFunction(Instruction, 0);
PIN_AddFiniFunction(Fini, 0);
PIN_StartProgram();
return 0;
}
This is my C file-
#include <stdio.h>
#include <test.h>
int cfunc(int a, int b)
{
return(a+b);
}
void cfunc2()
{
printf("Hello from C %d\n",cfunc(3,5));
}
This is my test.h file-
int cfunc(int, int);
void cfunc2(void);
The rest of the options are pin specific and I simply used them from the sample programs and feel that they don't need modifications (I hope so!)
However when I generate my shared object file I get this error-
obj-intel64/testcpp.o: In function `Fini(int, void*)':
testcpp.cpp:(.text+0x41): undefined reference to `cfunc2'
collect2: error: ld returned 1 exit status
cfunc2 is the function I am trying to call. I do not understand where I am going wrong. I am including the right options and arguments, but somehow this symbol is undefined. Any suggestions?
You use g++ to compile the test.c file. The g++ compiler driver invokes the C++ compiler for .c files, so your functions will have C++ linkage, not C linkage. There are several ways to address thos:
Compile test.c with gcc instead of g++.
Drop the extern "C" from the C++ source file, so that C++ linkage is used everywhere.
Put the extern "C" into the header file, so that applies to the definition in test.c, too.

undefined reference to `GDALAllRegister'

I have problem with gdal.Iam currently working on Ubuntu and the IDE is Eclipse CDT i have given my code below and i have also installed the gdal package but it gives build errors
#include <stdio.h>
#include<unistd.h>
#include "gdal/gdal_priv.h"
#include "gdal/cpl_conv.h"
#include<gdal/gdal.h>
int main(int argc,char* argv[])
{
void *hLib_Comm;
char exePath[800];
if(getcwd(exePath,sizeof(exePath))== NULL) {
printf("Exe path access error\n");
}
GDALDataset *poDataset;
GDALAllRegister();
poDataset = (GDALDataset *) GDALOpen( exePath, GA_ReadOnly );
if( poDataset == NULL )
{
printf("Exe path access error\n");;
}
}
///////////Bulid result///////////////////////////////////
14:51:47 **** Build of configuration Debug for project ReadFrmSoFile ****
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -lm -I/usr/include/gdal -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
../main.cpp: In function ‘int main(int, char**)’:
../main.cpp:17:8: warning: unused variable ‘hLib_Comm’ [-Wunused-variable]
Finished building: ../main.cpp
Building target: ReadFrmSoFile
Invoking: GCC C++ Linker
g++ -lm -L/usr/lib -L/usr/lib/ogdi -o "ReadFrmSoFile" ./main.o -lgdal
./main.o: In function `main':
/media/Local Disk/workspace2/ReadFrmSoFile/Debug/../main.cpp:24: undefined reference to `GDALAllRegister'
/media/Local Disk/workspace2/ReadFrmSoFile/Debug/../main.cpp:26: undefined reference to `GDALOpen'
collect2: ld returned 1 exit status
make: *** [ReadFrmSoFile] Error 1
//////////////////////////////////////////////
Please Help Me......

Undefined reference to 'main'

You got to love linker errors *sarcasm*. Any way, I am developing a psp game using the psp port of allegro which came with pspsdk. And after I fixed all the other undefined references this one stumps me. The full error message and makefile and code below:
Error details
1>------ Build started: Project: PSP Pong, Configuration: Debug Win32 ------
1> psp-g++ -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150 -c -o main.o main.cpp
1> psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150 -L. -LC:/pspsdk/psp/sdk/lib main.o -lalleg -lpspgu -lpspirkeyb -lm -lpsppower -lpspaudio -lpsprtc -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o main.elf
1> c:/pspsdk/bin/../lib/gcc/psp/4.3.5/../../../../psp/lib/crt0.o: In function `_main':
1> ../../../../pspsdk/src/startup/crt0.c (86) : undefined reference to `main'
1> C:\pspsdk\bin\make: *** [main.elf] Error 1
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
MakeFile
TARGET = main
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = PSP Pong
LIBS = -lalleg -lpspgu -lpspirkeyb -lm -lpsppower -lpspaudio -lpsprtc
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
main.cpp
#include <allegro.h>
int main()
{
allegro_init();
install_mouse();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT,480,272,0,0);
clear_bitmap(screen);
while (!(mouse_b & 2))
{
poll_mouse();
putpixel(screen,mouse_x,mouse_y,0xFFFFFFFF);
vsync();
}
clear_bitmap(screen);
return 0;
}
END_OF_MAIN();
P.S I think the linker is not talking about the main function in main.cpp but some other main but I have no clue so any advice, corrections, any thing to help me solve this will be appreciated.
Just before including allegro, try adding this define:
#define ALLEGRO_NO_MAGIC_MAIN
Source:
http://allegro-psp.webcindario.com/
Check out the source of crt0.c
It has a definition of main that it can't see because of the name mangling "magic" that END_OF_MAIN() does.
http://www.jbox.dk/sanos/source/lib/crt0.c.html
Try putting
#define ALLEGRO_NO_MAGIC_MAIN
at the start of things.
Try changing your main function definition to:
extern "C"
int main(int argc, char * argv[])
See if that helps things.

can i use CLucene and the Cue Sheet Parser together?

i'm trying to use clucene-0.9.21b and libcue-1.3.0 in Qt Creator on Kubuntu Lucid. this code is compilable:
project.pro
SOURCES += main.cpp
LIBS += -lcue
INCLUDEPATH += /usr/include/libcue-1.3/libcue
main.cpp
extern "C" {
#include <libcue.h>
}
int main(int argc, char *argv[]) {
return 0;
}
so is this:
project.pro
SOURCES += main.cpp
LIBS += -clucene
main.cpp
#include <CLucene.h>
int main(int argc, char *argv[]) {
return 0;
}
but not this one:
project.pro
SOURCES += main.cpp
LIBS += -lcue \
-clucene
INCLUDEPATH += /usr/include/libcue-1.3/libcue
main.cpp
extern "C" {
#include <libcue.h>
}
#include <CLucene.h>
int main(int argc, char *argv[]) {
return 0;
}
the latter generates the following errors:
Running build steps for project project...
Configuration unchanged, skipping QMake step.
Starting: /usr/bin/make -w
make: Entering directory `/home/user/project/project'
/usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile project.pro
make: Leaving directory `/home/user/project/project'
make: Entering directory `/home/user/project/project'
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/libcue-1.3/libcue -I. -o main.o main.cpp
In file included from /usr/include/sys/stat.h:107,
from /usr/include/CLucene/StdHeader.h:76,
from /usr/include/CLucene.h:11,
from main.cpp:5:
/usr/include/bits/stat.h:88: error: field ‘st_atim’ has incomplete type
/usr/include/bits/stat.h:89: error: field ‘st_mtim’ has incomplete type
/usr/include/bits/stat.h:90: error: field ‘st_ctim’ has incomplete type
/usr/include/bits/stat.h:149: error: field ‘st_atim’ has incomplete type
/usr/include/bits/stat.h:150: error: field ‘st_mtim’ has incomplete type
/usr/include/bits/stat.h:151: error: field ‘st_ctim’ has incomplete type
main.cpp:6: warning: unused parameter ‘argc’
main.cpp:6: warning: unused parameter ‘argv’
make: *** [main.o] Error 1
make: Leaving directory `/home/user/project/project'
Exited with code 2.
Error while building project project
When executing build step 'Make'
why is that and how to make it work?
Ok, this time I got a chance to actually try it. Problem seems to be that libcue has a file called time.h in its include folder. So if you compile with -I/usr/include/libcue-1.4/libcue then you end up with libcue's time.h instead of libc's.
This works for me:
extern "C" {
#include <libcue/libcue.h>
}
#include <CLucene.h>
int main(int argc, char *argv[]) {
return 0;
}
and obviously compiling with -I/usr/include/libcue-1.4/ instead of -I/usr/include/libcue-1.4/libcue
What happens if you swap the cue and clucene includes around? It could be a problem with include order and I suspect mixing c and c++ may make include order even more important