2

I want to create and compile C++ project from sources using Eclipse(on Linux) and got

identifier "HANDLE" is undefined

for the code:

#include "Types.h"

#ifdef __cplusplus
extern "C" {
#endif

WRes HandlePtr_Close(HANDLE *h);
...

How to fix this error? Is HANDLE something standard in C?

Here the make the file with help of it everything is compiling well but I want to compile using eclipse project:

# Final names of binaries
EXECUTABLE = Bin/zipsample
SO_LIBRARY = Bin/libzip.so

# C & C++ compiler
#CC       = gcc
#CXX      = g++-4.8
CC        = clang
CXX       = clang++
CFLAGS    = -fPIC -Wno-enum-conversion -O3
CXXFLAGS  = -fPIC -std=c++11 -O3

# Linker flags
LDFLAGS   = -pthread

# Sources of external libraries
SRC_ZLIB  = $(wildcard Source/ZipLib/extlibs/zlib/*.c)
SRC_LZMA  = $(wildcard Source/ZipLib/extlibs/lzma/unix/*.c)
SRC_BZIP2 = $(wildcard Source/ZipLib/extlibs/bzip2/*.c)

# ZipLib sources
SRC = \
        $(wildcard Source/ZipLib/*.cpp)        \
        $(wildcard Source/ZipLib/detail/*.cpp)

# Object files          
OBJS = \
        $(SRC:.cpp=.o)     \
        $(SRC_ZLIB:.c=.o)  \
        $(SRC_LZMA:.c=.o)  \
        $(SRC_BZIP2:.c=.o)

# Rules
all: $(EXECUTABLE) $(SO_LIBRARY)

$(EXECUTABLE): $(OBJS)
    $(CXX) $(CXXFLAGS) $(LDFLAGS) Source/Sample/Main.cpp -o $@ $^

$(SO_LIBRARY): $(OBJS)
    $(CXX) $(LDFLAGS) -shared -o $@ $^

%.o: %.cpp
    $(CXX) $(CXXFLAGS) -c $< -o $@

%.o: %.c
    $(CC) $(CFLAGS) -c $< -o $@

clean:
    rm -rf `find Source -name '*.o'` ziplib.tar.gz Bin/*.zip Bin/out* $(EXECUTABLE) $(SO_LIBRARY)

tarball:
    tar -zcvf ziplib.tar.gz *
Brans Ds
  • 4,039
  • 35
  • 64
  • Relevant: https://stackoverflow.com/questions/1303123/what-is-a-handle-in-c – Germán Aug 14 '18 at 09:19
  • 2
    You are using c++, ask for standard C and added both C and C++ tags to your question. Please decide which language you want to use. They are very different languages. – Gerhardh Aug 14 '18 at 09:20
  • 2
    HANDLE is a common type used by the Windows API. It is not standard C. The Windows API does not work in Linux and vice versa. – Lundin Aug 14 '18 at 09:22
  • This code is compiled successfully on Linux using make. And see no typedef of HANDLE in the repository https://bitbucket.org/search?q=repo%3Aziplib%20HANDLE&account=%7Be42a1629-26db-4e05-8836-249fb1321f42%7D. How if this is not standart C? – Brans Ds Aug 14 '18 at 09:27
  • @Gerhardh I am interested in C++ project but the code that is not compiled is under extern "C" {} so both – Brans Ds Aug 14 '18 at 09:29
  • This code is Windows specific and is located in `lzma/Threads.c` and Makefile only includes `lzma/unix/*.c`. So, it is just not used in non-windows builds. – dewaffled Aug 14 '18 at 09:36
  • @dewaffled thank you. Got it! – Brans Ds Aug 14 '18 at 09:40

0 Answers0