I've cloned the LuaJIT git repo and built it with:
make STATIC_CC="musl-gcc" BUILDMODE="static"
Then, I compiled a simple Lua "hello world" script into a C header file:
luajit -b test.lua test.h
test.h:
#define luaJIT_BC_test_SIZE 52
static const unsigned char luaJIT_BC_test[] = {
27,76,74,2,10,45,2,0,3,0,2,0,4,54,0,0,0,39,2,1,0,66,0,2,1,75,0,1,0,20,72,101,
108,108,111,32,102,114,111,109,32,76,117,97,33,10,112,114,105,110,116,0
};
After that, I wrote a simple C wrapper by following the official example, test.c:
#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "test.h"
int main(void) {
int error;
lua_State *L = lua_open();
luaL_openlibs(L);
error = luaL_loadbuffer(L, (const char *) luaJIT_BC_test, luaJIT_BC_test_SIZE, "test") || lua_pcall(L, 0, 0, 0);
if (error) {
fprintf(stderr, "%s", lua_tostring(L, -1));
lua_pop(L, 1);
}
lua_close(L);
return 0;
}
But when I try to build it, it crashes with an error:
$ musl-gcc -static -ILuaJIT/src -LLuaJIT/src -o test test.c -lluajit
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `_Unwind_Find_FDE':
(.text+0x1953): undefined reference to `_dl_find_object'
collect2: error: ld returned 1 exit status
It's related to libgcc, so I tried building everything with musl-clang, but still got the same error. Can someone explain what I'm missing here?
Figured it out - I needed to build LuaJIT with TARGET_XCFLAGS=-DLUAJIT_NO_UNWIND like so:
make STATIC_CC="musl-gcc" BUILDMODE="static" TARGET_XCFLAGS=-DLUAJIT_NO_UNWIND
I guess this just disables C++ exceptions support, but I'm not sure what the real implications are. Seems to work fine, for now.
Visual Studio Code project
CMake connects files
As a beginner I want to integrate testlib.h
and testlib.c which I can call in the main.c
testlib.c and .h should also call boot.h - but this doesn't work!
Including my teslib.h and testlib.c in main,c works. But In testlib.h I need access e.g. to boot.h ... but I cannot include this file!
Here is the code:
#include "testlib.h"
#include <stdint.h>
#include "boot.h" // why there comes an error when I want to include this?
#include <stddef.h>
int f123(void){
int a = 2;
return a;
}
void print_uart_22(const char text[])
{
int a;
(void)a;
(void)text;
}
Why there comes the error message?
There must be something wrong with the paths...
but main.c is next to testlib.h
main.c also includes "boot.h" without error
/testlib.c:4:10: fatal error: boot.h: No such file or directory
[build] #include "boot.h"
[build] ^~~~~~~~
[build] compilation terminated.
Why?
hahaaha
main.c is located next to testlib.h and testlib.c!
main.c includes also boot.h and there is no error.
Background
I am trying to build a sample REST api app for Rasbian running on Raspberry 3. I used cpprestsdk.
Sample contains the following header file:
#include <condition_variable>
#include <mutex>
#include <iostream>
static std::condition_variable _condition;
static std::mutex _mutex;
namespace cfx {
class InterruptHandler {
public:
static void hookSIGINT() {
signal(SIGINT, handleUserInterrupt);
}
static void handleUserInterrupt(int signal){
if (signal == SIGINT) {
std::cout << "SIGINT trapped ..." << '\n';
_condition.notify_one();
}
}
static void waitForUserInterrupt() {
std::unique_lock<std::mutex> lock { _mutex };
_condition.wait(lock);
std::cout << "user has signaled to interrup program..." << '\n';
lock.unlock();
}
};
}
Issue
When compiling on MacOS, no problem occurs.
When compiling in rasbian however, I get error: 'SIGINT' was not declared in this scope error.
It is clear that SIGINT definition - #define SIGINT 2 or similar - is not reachable when compiling on rasbian.
Question
Why I am getting this error on rasbian but not on macOS? Is it because compiler cannot locate signal.h?
I made sure that include_directories in CMakeLists.txt contains required include paths.
UPDATE
Error resolved when I manually added #include <csignal>.
You haven't included signal.h.
You're including some C++ standard library headers, and as a side effect on MacOS, these happen to include signal.h. However, that isn't specified to happen so you can't rely on it working in different implementations of those headers.
Try adding:
#include <signal.h>
at the top.
On Linux the header file to include is
#include <signal.h>
On MacOS the equivalent header file to include is
#include <csignal.h>
Depending on your OS, header files always change. They should both do the same thing though
I am new to Tesseract API. Currently I am running the sample program from the Wiki on Visual Studio 2013, and the program is as follows.
#include "leptonica\allheaders.h"
#include "iostream"
#include "api\baseapi.h"
#include "stdio.h"
using namespace std;
using namespace tesseract;
int main(int argc, char** argv)
{
char* outText;
TessBaseAPI *api = new TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng"))
{
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
// Open input image with leptonica library
Pix *image = pixRead("/usr/src/tesseract-3.02/phototest.tif");
api->SetImage(image);
// Get OCR result
outText = api->GetUTF8Text();
printf("OCR output:\n%s", outText);
// Destroy used object and release memory
api->End();
delete[] outText;
pixDestroy(&image);
return 0;
}
When I compile this with VS2013, I get the following errors.
1>------ Build started: Project: OCRTest, Configuration: Debug Win32 ------
1> main.cpp
1>c:\tesseract-build\include\leptonica\pix.h(209): warning C4305: 'initializing' : truncation from 'double' to 'const l_float32'
1>c:\tesseract-build\include\leptonica\pix.h(211): warning C4305: 'initializing' : truncation from 'double' to 'const l_float32'
1>c:\tesseract-build\tesseract-ocr\api\baseapi.h(32): fatal error C1083: Cannot open include file: 'platform.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I believe I have not built the tesseract source properly, but I cannot be sure. Also, declaring
TessBaseAPI * api = new TessBaseAPI()
throws up errors such as 'type specifier expected' when cursor is moved over TessBaseAPI(). Help would be greatly appreciated, and thank you in advance!
Assuming that you are using Tesseract 3.02.02 & leptonica 1.68 library.
Follow these steps.
Remember to check Tesseract Development files option when installing Tesseract
Add below Include folders in Project solutions -> VC++ Directories
C:\Program Files\Tesseract-OCR\include
C:\Program Files\Tesseract-OCR\include\tesseract
C:\Program Files\Tesseract-OCR\include\leptonica
Add below lib folder in Project solutions -> VC++ Directories
C:\Program Files\Tesseract-OCR\lib
Add additional dependencies in Configuration Properties -> Linker->Input ->Additional Dependencies
libtesseract302.lib
libtesseract302d.lib
liblept168.lib
liblept168d.lib
General program structure
>
> #include <baseapi.h>
> #include <allheaders.h>
> #include <iostream>
>
> using namespace std;
>
> int main(void)
> {
> tesseract::TessBaseAPI api;
> //...
> }
>
>
I am trying to build my first opencv application, I added the include directories and the library directories and then added the linking input which is some opencv.lib files after running this code:
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat im = imread("c:/full/path/to/lena.jpg");
if (im.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
imshow("Image", im);
waitKey(0);
}
but I got this error:
The program can't start because libgcc_s_dw2-1.dll is missing from your computer.
the error list include:
Warning 1 warning D9002: ignoring unknown option '-static-libgcc' c:\Users\Kato\documents\visual studio 2010\Projects\cvtest\cvtest\cl cvtest
I added -static-libgcc to command line additional options but the same error.