Makefile - 主要错误的隐式输入/启动

时间:2015-12-23 21:34:32

标签: c++ makefile

我从makefile获取以下输出。我的主要目标是编译目录中的所有内容。我希望将来有更多的cpp文件。非常感谢任何提示或建议!

输出:

g++ `pkg-config --libs --cflags opencv libexif` main.cpp -o main.o
g++ `pkg-config --libs --cflags opencv libexif` Image.cpp -o Image.o
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Image.o] Error 1

当前文件列表: main.cpp,Image.h,Image.cpp

这是makefile:

CC=g++
CFLAGS= `pkg-config --libs --cflags opencv libexif`
LDFLAGS= `pkg-config --libs --cflags opencv libexif`
SOURCES=main.cpp Image.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=CvHelloWorld

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) 
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
    $(CC) $(CFLAGS) $< -o $@

clean:
    rm *.o

1 个答案:

答案 0 :(得分:0)

根据@5gon12eder的建议,您应该使用&#39; -c&#39;。

Private InvalidColor
Private ValidColor
Private Sub UserForm_Initialize()
    InvalidColor = RGB(255, 180, 180)
    ValidColor = RGB(180, 255, 180)
    TextBox1.BackColor = InvalidColor
    TextBox2.BackColor = InvalidColor
    TextBox3.BackColor = InvalidColor
End Sub
Private Sub TextBox1_AfterUpdate()
    RunValidation Me.ActiveControl
End Sub
Private Sub TextBox2_AfterUpdate()
    RunValidation Me.ActiveControl
End Sub
Private Sub TextBox3_AfterUpdate()
    RunValidation Me.ActiveControl
End Sub
Private Sub RunValidation(ByRef tb As MSForms.TextBox)
    If Len(tb.Value) > 0 Then
        tb.BackColor = ValidColor
    Else
        tb.BackColor = InvalidColor
    End If

    If Len(TextBox1.Value) * Len(TextBox2.Value) * Len(TextBox3.Value) = 0 Then
        CommandButton1.Enabled = False
        Label1.Visible = True
    Else
        CommandButton1.Enabled = True
        Label1.Visible = False
    End If
End Sub
Private Sub CommandButton1_Click()
    Me.Hide
End Sub

如果您之前解释 pkg-config 结果,则调试会更容易:

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

[...]

CFLAGS  := $(shell pkg-config --cflags opencv libexif)
LDFLAGS := $(shell pkg-config --libs opencv libexif)
SOURCES := $(wildcard *.cpp)