LLVM Error : External function could not be resolved

匿名 (未验证) 提交于 2019-12-03 07:50:05

问题:

I am reading the LLVM's Kaleidoscope tutorial (http://llvm.org/docs/tutorial/index.html).

I wanted to compile and test the language. After some compiler's errors (EngineBuilder and Module's constructor, linking libs...), the example program was built. Then, I tried the language. I got a few problems with InitializeNativeTargets, DataLayoutPass... But I managed to correct them.

Howewer, I don't manage to resolve one error. When I write extern printd(x); printd(5);, the program doesn't work : "LLVM ERROR : Program used external function 'printd' which could not be resolved".

I looked for the solution on the net. I read a lot of webpages, but nothing worked.

How can I resolve this problem ? Why LLVM can't find the external function 'printd', which is included in the program ? Thanks in advance for your answer.

The used code : https://docs.google.com/document/d/1Qb-zUGaUUIF354uFCXv1iuq8n_rjya6IHDW4WCPWN_4/edit?usp=sharing

The .pro file (Qt Creator) :

QT       += core QT       -= gui TARGET = Kaleidoscope CONFIG   += console CONFIG   -= app_bundle TEMPLATE = app SOURCES += main.cpp INCLUDEPATH += /home/alainetflo/Documents/me/C++/LLVM/llvm-3.5.0.src/include DEPENDPATH += /home/alainetflo/Documents/me/C++/LLVM/llvm-3.5.0.src/include  LIBS += `llvm-config --ldflags --libs all --system-libs` -Wl,-no-as-needed  QMAKE_CFLAGS += -m32 QMAKE_CXXFLAGS += -rdynamic -std=c++11 -O3 

I use GCC 4.8.2, LLVM 3.5 and Qt 5.3.1 on Ubuntu 14.04 32bits.

回答1:

Finally, I found a great link on the net : http://koichitamura.blogspot.fr/2011/01/since-i-went-to-held-several-weeks-ago.html.

The error came from the wrong place of the -rdynamic argument in the .pro file (-rdynamic must be after the linking options). You need this argument because (GCC man page) :

This instructs the linker to add all symbols, not only used ones, to the dynamic symbol table.

I changed the .pro file :

QT       += core     QT       -= gui     TARGET = Test01 CONFIG   += console CONFIG   -= app_bundle     TEMPLATE = app    SOURCES += main.cpp     INCLUDEPATH += /home/alainetflo/Documents/me/C++/LLVM/llvm-3.5.0.src/include DEPENDPATH += /home/alainetflo/Documents/me/C++/LLVM/llvm-3.5.0.src/include INCLUDEPATH += /usr/include/i386-linux-gnu/c++/4.8 \ /usr/include/c++/4.8  LIBS += `llvm-config --ldflags --libs all --system-libs` -Wl,-no-as-needed -rdynamic  QMAKE_CFLAGS += -m32  QMAKE_CXXFLAGS += -g -std=c++11 -O3 

In this way, the program works with no error ! (The tutorial's example runs (http://llvm.org/docs/tutorial/LangImpl6.html#kicking-the-tires))



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!