Linking cURL in Makefile

前端 未结 2 389
你的背包
你的背包 2021-01-13 14:59

I need link cURL in Ubuntu 11.04 after installed cURL by source code.

.

Correction of the PROBLEM

First I discovered that the -l must

相关标签:
2条回答
  • 2021-01-13 15:15

    This should do the job. You didn't really link to cURL before.

    build: $(SOURCES)
        $(CXX) -o $(OUT) $(INCLUDE) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SOURCES)
    

    Notice the added $(LDLIBS).

    Oh, I should add that basically what happens is that you throw overboard the built-in rules of GNU make (see output of make -np) and define your own. I would suggest that you either use the built-in ones if you want to rely on the respective variables to be sufficient to control the build or that you still split it up into compilation and link step for the sake of brevity.

    Brief explanation: GNU make comes with a rule that states how to make a .o file from a .cpp (or .c) file. So your make file could perhaps be rewritten to (approx.)

    # Testing cURL
    # MAKEFILE
    
    # C++ Compiler (Default: g++)
    CXX = g++
    CFLAGS = -Wall -Werror
    
    # Librarys
    INCLUDE = -I/usr/local/include
    LDFLAGS = -L/usr/local/lib 
    LDLIBS = -lcurl
    
    # Details
    SOURCES = src/main.cpp
    OUT = test
    
    .PHONY: all
    
    all: build
    
    $(OUT): $(patsubst %.cpp,%.o,$(SOURCES))
    

    This should generate the binary with the name test (contents of OUT) and makes otherwise use of the built-in rules. Make infers from the use of .o files that there must be source files, will look for them and compile them. So implicitly this build will run one invocation for each .cpp file and one for the linking step.

    0 讨论(0)
  • 2021-01-13 15:33

    You are missing slashes at the start of the paths below

    -I/usr/local/include
    -L/usr/local/lib
    
    0 讨论(0)
提交回复
热议问题