Coder Social home page Coder Social logo

c++ compile (g++) fails about fpc HOT 4 OPEN

kagiannis avatar kagiannis commented on August 25, 2024
c++ compile (g++) fails

from fpc.

Comments (4)

kagiannis avatar kagiannis commented on August 25, 2024

Hello

extern "C" is used when fpc.c is compiled as c but then included by a c++ application

To make it work you should either compile fpc.c seperately as c application

gcc -Wall -O2 -DNDEBUG -c fpc.c -o fpc.o 

and then link it with c++

g++ -Wall -O2 -DNDEBUG cli.c fpc.o -o fpc

or if you want to compile both with g++ you should remove extern "C"

from fpc.

kagiannis avatar kagiannis commented on August 25, 2024

Also you should notice that fpc.c uses variable length arrays that they are not present in standard c++. They are included only in standard c (C99 and above). So it can be compiled as c++ only with compilers that support variable length arrays as extension like g++ and clang++.

from fpc.

pulmark avatar pulmark commented on August 25, 2024

Thanks for the info. I made a static lib Makefile for fpc.c by using g++ and it works. Probably will use it instead of just using the #include "fpc.c" trick.

from fpc.

pulmark avatar pulmark commented on August 25, 2024

Makefile for libfpc.a:

CC = g++
TARGET = libfpc.a
CFLAGS= -pipe -fPIC -O3 -g -Wall -c -march=native -mtune=native

INC = -I./
OBJ_DIR=./obj
OUT_DIR=./
SRC_DIR=./

#Lib for fpc.c
FILES = $(SRC_DIR)/fpc.c
$(TARGET): $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(FILES))
ar -rcs -o $(OUT_DIR)/$@ $^

#Compiling every *.c to *.o
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c dirmake
$(CC) -c $(INC) $(CFLAGS) -o $@ $<

dirmake:
@mkdir -p $(OUT_DIR)
@mkdir -p $(OBJ_DIR)

clean:
rm -f $(OBJ_DIR)/*.o $(OUT_DIR)/$(TARGET)

rebuild: clean build

from fpc.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.