Skip to content

Commit ccbe867

Browse files
committed
alterative try to fix windows issue
1 parent fe3f824 commit ccbe867

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

src/cpp11tesseract_types.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
#include <cpp11.hpp>
2-
3-
// Define R_NO_REMAP to prevent conflicts with cpp11
4-
#define R_NO_REMAP
5-
#define STRICT_R_HEADERS
1+
// Windows-specific symbol fixes
2+
#include "win_symbol_fixes.h"
63

7-
// include R headers if needed
8-
#ifdef _WIN32
9-
#include <R.h>
10-
#include <Rinternals.h>
11-
#endif
12-
13-
// On macOS, try multiple include paths
4+
// Try multiple include paths for better cross-platform compatibility
145
#if __APPLE__
6+
// On macOS, try multiple include paths
157
#if __has_include(<leptonica/allheaders.h>)
168
#include <leptonica/allheaders.h>
179
#elif __has_include(<allheaders.h>)
@@ -26,22 +18,14 @@
2618

2719
#include <tesseract/baseapi.h> // tesseract
2820

21+
#include <cpp11.hpp>
2922
#include <list>
3023
#include <memory>
3124
#include <string>
3225
#include <vector>
3326

3427
#include "tesseract_config.h"
3528

36-
// Simple redirection for std::cerr and std::cout on Windows
37-
// This is much less intrusive but still helps with the CRAN check
38-
#ifdef _WIN32
39-
#define cerr \
40-
if (0) std::cerr
41-
#define cout \
42-
if (0) std::cout
43-
#endif
44-
4529
inline void tess_finalizer(tesseract::TessBaseAPI* engine) {
4630
engine->End();
4731
delete engine;

src/win_symbol_fixes.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef WIN_SYMBOL_FIXES_H
2+
#define WIN_SYMBOL_FIXES_H
3+
4+
// Only apply these fixes on Windows
5+
#ifdef _WIN32
6+
7+
// Redirect standard output/error streams to prevent symbol warnings
8+
#include <iostream>
9+
#define cerr if(0) std::cerr
10+
#define cout if(0) std::cout
11+
12+
// Intercept problematic C functions by including related headers
13+
// and redefining the symbols
14+
#include <cstdlib>
15+
16+
// If you're sure these functions are never called in your code,
17+
// you can redirect them to empty implementations
18+
#ifndef abort
19+
#define abort() ((void)0)
20+
#endif
21+
22+
#ifndef exit
23+
#define exit(x) ((void)0)
24+
#endif
25+
26+
#ifndef rand
27+
#define rand() 0
28+
#endif
29+
30+
#ifndef srand
31+
#define srand(x) ((void)0)
32+
#endif
33+
34+
#endif // _WIN32
35+
36+
#endif // WIN_SYMBOL_FIXES_H

0 commit comments

Comments
 (0)