openssl/conf.h file not found error on MacOS - macos

When trying to compile code (using cmake), I keep getting this error :
In file included from /usr/local/include/cpprest/http_client.h:68:
In file included from /usr/local/include/boost/asio/ssl.hpp:18:
In file included from /usr/local/include/boost/asio/ssl/context.hpp:23:
In file included from /usr/local/include/boost/asio/ssl/context_base.hpp:19:
/usr/local/include/boost/asio/ssl/detail/openssl_types.hpp:23:10: fatal error: 'openssl/conf.h' file not found
#include <openssl/conf.h>
^~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/httpclient.dir/http_client.cpp.o] Error 1
make[1]: *** [CMakeFiles/httpclient.dir/all] Error 2
make: *** [all] Error 2
I have tried to follow these links but nothing helps :
Fatal Error: 'openssl/conf.h' file not found
and
'openssl/conf.h' file not found error on on MacOS Big Sur and 'openssl/conf.h' file not found error on MacOS Sierra
Following is my cmake :
cmake_minimum_required(VERSION 3.9)
find_package(cpprestsdk REQUIRED)
set (CMAKE_CXX_STANDARD 11)
add_executable(httpclient http_client.cpp)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl#3)
#set(OPENSSL_LIBRARIES /usr/local/opt/openssl#3/lib)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl#3/*)
set(OPENSSL_LIBRARIES /usr/local/opt/openssl#3/lib)
include(FindOpenSSL)
target_include_directories(httpclient INTERFACE ${OPENSSL_ROOT_DIR}/include)
target_link_libraries(httpclient PRIVATE cpprestsdk::cpprest
openssl)
I have also tried setting LDFLAGS and CPPFLAGS, it din't help.
Also tried re-installing boost - din't work.
Please help me understand how to resolve this.
Thanks!

I'm facing the same problem. Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.22)
project(Test)
set(CMAKE_CXX_STANDARD 14)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl) # it points to openssl#3
find_package(Boost COMPONENTS system filesystem REQUIRED)
find_package(cpprestsdk REQUIRED)
add_executable(Test main.cpp)
target_link_libraries(
Test
PRIVATE Boost::system
PRIVATE Boost::filesystem
)
Here is C++ test code (the Boost tutorial code):
#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <cpprest/http_msg.h> // the code can be compiled with this "include"
// #include <cpprest/http_client.h> // compilation with this "include" ends with the same openssl error
using boost::asio::ip::tcp;
std::string make_daytime_string()
{
using namespace std; // For time_t, time and ctime;
time_t now = time(0);
return ctime(&now);
}
int main() {
std::cout << "Ahoj" << std::endl;
try
{
boost::asio::io_context io_context;
tcp::acceptor acceptor(io_context, tcp::endpoint(tcp::v4(), 13));
for (;;)
{
tcp::socket socket(io_context);
acceptor.accept(socket);
std::string message = make_daytime_string();
boost::system::error_code ignored_error;
boost::asio::write(socket, boost::asio::buffer(message), ignored_error);
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
OS: macOS Monterey 12.4
XCODE: 13.4.1
Build tool: Ninja
IDE: CLion 2022.1.3
btw. According to https://github.com/microsoft/cpprestsdk documentation, the cmake configuration is minimalistic for cpprestsdk but it does not work on mac (on windows is a problem as well - cpprestsdk package -> #include <cpprest/http_listener.h> -> build error C2338 static_assert failed: 'type is not supported for extraction from a stream').

Related

Error while building a static Linux binary (with musl-libc) that includes LuaJIT

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.

Why is the library not included?

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.

SIGINT was not declared in this scope

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

Issue with declaring Tesseract OCR TessBaseAPI

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;
> //...
> }
>
>

opencv with visual studio 2010 error

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.

Resources