- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个链接到共享库(* .so)的小程序。但是当我尝试编译程序时,
我收到一条错误消息,提示“函数”的“ undefined reference ”
程序文件的内容。
user@ubuntu:~/Perforce/user_ubuntu_3105/wp/eng/main/src/libfc/37D03B6/bin$ cat test.cpp
#include <iostream>
#include <vector>
#include <memory>
#include "InfoModel.h"
int main()
{
libfc::InfoModel & model = libfc::InfoModel::instance();
return 0;
}
user@ubuntu:~/Perforce/user_ubuntu_3105/wp/eng/main/src/libfc/37D03B6/bin$ g++ -Wall -W -std=c++0x test.cpp -L. -lfc -o rst
test.cpp: In function ‘int main()’:
test.cpp:9:21: warning: unused variable ‘model’ [-Wunused-variable]
libfc::InfoModel & model = libfc::InfoModel::instance();
^
/tmp/ccFtLDxc.o: In function `main':
test.cpp:(.text+0x9): undefined reference to `libfc::InfoModel::instance()'
collect2: error: ld returned 1 exit status
user@ubuntu:~/Perforce/user_ubuntu_3105/wp/eng/main/src/libfc/37D03B6/bin$ nm --demangle libfc.so | grep InfoModel
0000000000007e40 t _GLOBAL__sub_I_InfoModel.cpp
00000000002464a0 b guard variable for libfc::InfoModel::instance()::instance_
0000000000010260 t libfc::InfoModel::add_unknown(unsigned int, unsigned short, unsigned short)
0000000000010520 t libfc::InfoModel::registerIEType(libfc::IEType const*)
000000000000f550 t libfc::InfoModel::add(libfc::InfoElement const&)
0000000000012980 t libfc::InfoModel::add(std::string const&)
0000000000010a60 t libfc::InfoModel::instance()
00000000000106f0 t libfc::InfoModel::initTypes()
00000000000108f0 t libfc::InfoModel::InfoModel()
00000000000108f0 t libfc::InfoModel::InfoModel()
0000000000027ae0 t libfc::InfoModel::~InfoModel()
0000000000027ae0 t libfc::InfoModel::~InfoModel()
0000000000010b00 t libfc::InfoModel::parseIESpec(std::string const&) const
000000000000ee80 t libfc::InfoModel::lookupIEType(unsigned int) const
000000000000ed40 t libfc::InfoModel::lookupIEType(std::string const&) const
000000000000ef20 t libfc::InfoModel::dump(std::ostream&) const
000000000000f0c0 t libfc::InfoModel::lookupIE(unsigned int, unsigned short, unsigned short) const
000000000000f1b0 t libfc::InfoModel::lookupIE(libfc::InfoElement const&) const
0000000000012840 t libfc::InfoModel::lookupIE(std::string const&) const
000000000000f410 t libfc::InfoModel::lookupIE2(unsigned int, std::string const&, unsigned short, unsigned short) const
00000000002463a0 b libfc::InfoModel::instance()::instance_
user@ubuntu:~/Perforce/user_ubuntu_3105/wp/eng/main/src/libfc/37D03B6/bin$ readelf -s libfc.so | grep FILE
34: 0000000000000000 0 FILE LOCAL DEFAULT ABS EncodePlan.cpp
43: 0000000000000000 0 FILE LOCAL DEFAULT ABS InfoElement.cpp
49: 0000000000000000 0 FILE LOCAL DEFAULT ABS FileExportDestination.cpp
53: 0000000000000000 0 FILE LOCAL DEFAULT ABS IETemplate.cpp
58: 0000000000000000 0 FILE LOCAL DEFAULT ABS IEType.cpp
104: 0000000000000000 0 FILE LOCAL DEFAULT ABS InfoModel.cpp
113: 0000000000000000 0 FILE LOCAL DEFAULT ABS libfc.cpp
118: 0000000000000000 0 FILE LOCAL DEFAULT ABS PlacementExporter2.cpp
124: 0000000000000000 0 FILE LOCAL DEFAULT ABS PlacementTemplate.cpp
129: 0000000000000000 0 FILE LOCAL DEFAULT ABS TemplateState.cpp
135: 0000000000000000 0 FILE LOCAL DEFAULT ABS test.cpp
141: 0000000000000000 0 FILE LOCAL DEFAULT ABS UdpSocketExportDestinatio
149: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
158: 0000000000000000 0 FILE LOCAL DEFAULT ABS BasicOctetArray.cpp
159: 0000000000000000 0 FILE LOCAL DEFAULT ABS Exception.cpp
160: 0000000000000000 0 FILE LOCAL DEFAULT ABS ExportError.cpp
161: 0000000000000000 0 FILE LOCAL DEFAULT ABS FormatError.cpp
162: 0000000000000000 0 FILE LOCAL DEFAULT ABS IESpecError.cpp
163: 0000000000000000 0 FILE LOCAL DEFAULT ABS error_code.cpp
187: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
190: 0000000000000000 0 FILE LOCAL DEFAULT ABS
PLUGIN = libfc
OUTPUT_DIR = bin
OUTPUT = $(OUTPUT_DIR)/$(PLUGIN).so
PLUG_SRC = src
EXCEPTION_SRC = src/exceptions
CPP = g++
THIRD_PARTY_DIR = ../../../../../third-party
BOOST_DIR = $(THIRD_PARTY_DIR)/boost/1.66.0
G3LOG_DIR = $(THIRD_PARTY_DIR)/g3log/2017-07-18_g3log
FLAGS = -c -std=c++0x -fvisibility-inlines-hidden -pthread \
-fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive
MACROS = -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_
INCLUDES = -I$(PLUG_SRC) \
-I$(EXCEPTION_SRC) \
-I$(BOOST_DIR) \
-I$(G3LOG_DIR)/src \
-I$(G3LOG_DIR)/include
LFLAGS = -shared -lpthread -L$(G3LOG_DIR)/build -lg3logger
CPPFLAGS = $(FLAGS) $(MACROS) $(INCLUDES)
LDFLAGS = $(LFLAGS)
ifeq ($(BUILD),DEBUG)
CPPFLAGS += -ggdb3 -O0
else
CPPFLAGS += -g -Wall -O2 -D NDEBUG
LDFLAGS += -flto
endif
# compile static boost lib as
# ./bjam --toolset=gcc address-model=64 cxxflags=-fPIC cflags=-fPIC
variant=release threading=multi link=static --with-system stage
BOOST_LIBS = $(BOOST_DIR)/stage/lib/libboost_system.a
OBJ_DIR = obj
PLUG_OBJS = $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(subst
$(PLUG_SRC)/,,$(wildcard $(PLUG_SRC)/*.cpp)))
FRAME_OBJS = $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(subst
$(EXCEPTION_SRC)/,,$(wildcard $(EXCEPTION_SRC)/*.cpp)))
VPATH = $(PLUG_SRC) $(EXCEPTION_SRC)
all: $(PLUGIN)
$(PLUG_OBJS): $(OBJ_DIR)/%.o: %.cpp
$(CPP) $(CPPFLAGS) -o $@ $<
$(FRAME_OBJS): $(OBJ_DIR)/%.o: %.cpp
$(CPP) $(CPPFLAGS) -o $@ $<
$(PLUG_OBJS) $(FRAME_OBJS): | $(OBJ_DIR)
$(OBJ_DIR):
mkdir $(OBJ_DIR)
$(OUTPUT): | $(OUTPUT_DIR)
$(OUTPUT_DIR):
mkdir $(OUTPUT_DIR)
$(PLUGIN): $(PLUG_OBJS) $(FRAME_OBJS) $(OUTPUT)
$(CPP) $(LDFLAGS) -o $(OUTPUT) $(PLUG_OBJS) $(FRAME_OBJS) $(BOOST_LIBS)
.PHONY: clean
clean:
rm -f $(PLUG_OBJS) $(FRAME_OBJS) $(OUTPUT)
rm -rf $(OBJ_DIR)
rm -rf $(OUTPUT_DIR)
user@ubuntu:~/Perforce/sselvam_ubuntu_3105/wp/eng/main/src/libfc/37D03B6$ make all
mkdir obj
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/BasicOctetArray.o src/BasicOctetArray.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/EncodePlan.o src/EncodePlan.cpp
src/EncodePlan.cpp: In constructor ‘libfc::EncodePlan2::EncodePlan2(const libfc::PlacementTemplate*)’:
src/EncodePlan.cpp:90:9: warning: unused variable ‘ie_present’ [-Wunused-variable]
bool ie_present
^
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/FileExportDestination.o src/FileExportDestination.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/IETemplate.o src/IETemplate.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/IEType.o src/IEType.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/InfoElement.o src/InfoElement.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/InfoModel.o src/InfoModel.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/libfc.o src/libfc.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/PlacementExporter2.o src/PlacementExporter2.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/PlacementTemplate.o src/PlacementTemplate.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/TemplateState.o src/TemplateState.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/UdpSocketExportDestination.o src/UdpSocketExportDestination.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/Exception.o src/exceptions/Exception.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/ExportError.o src/exceptions/ExportError.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/FormatError.o src/exceptions/FormatError.cpp
g++ -c -std=c++0x -fvisibility-inlines-hidden -pthread -fPIC -fvisibility=hidden -fno-omit-frame-pointer -fpermissive -D_libfc_HAVE_NIXIO -U_libfc_HAVE_LOG4CPLUS_ -U_libfc_HAVE_WANDIO_ -Isrc -Isrc/exceptions -I../../../../../third-party/boost/1.66.0 -I../../../../../third-party/g3log/2017-07-18_g3log/src -I../../../../../third-party/g3log/2017-07-18_g3log/include -g -Wall -O2 -D NDEBUG -o obj/IESpecError.o src/exceptions/IESpecError.cpp
mkdir bin
g++ -shared -lpthread -L../../../../../third-party/g3log/2017-07-18_g3log/build -lg3logger -flto -o bin/libfc.so obj/BasicOctetArray.o obj/EncodePlan.o obj/FileExportDestination.o obj/IETemplate.o obj/IEType.o obj/InfoElement.o obj/InfoModel.o obj/libfc.o obj/PlacementExporter2.o obj/PlacementTemplate.o obj/TemplateState.o obj/UdpSocketExportDestination.o obj/Exception.o obj/ExportError.o obj/FormatError.o obj/IESpecError.o ../../../../../third-party/boost/1.66.0/stage/lib/libboost_system.a
最佳答案
libfc::InfoModel & model = libfc::InfoModel::instance();
^
/tmp/ccFtLDxc.o: In function `main':
test.cpp:(.text+0x9): undefined reference to `libfc::InfoModel::instance()'
collect2: error: ld returned 1 exit status
-fvisibility=hidden
(和 friend ):
$ nm -gCD ...
0000000000012980 t libfc::InfoModel::add(std::string const&)
0000000000010a60 t libfc::InfoModel::instance()
00000000000106f0 t libfc::InfoModel::initTypes()
...
InfoModel
类,它不再可见。我猜你手动添加了
-fvisibility=hidden
(和 friend )但没有编辑源文件并添加
DLL_PUBLIC
(根据
GCC Visibility 维基)。
-fvisibility=hidden
(和 friend )。然后,当您构建使用静态存档的共享对象/插件时,请使用
-fvisibility=hidden
(和 friend )并包括
-Wl,--exclude-libs,ALL
链接器标志。额外的链接器标志将确保您不会从静态文件中重新导出符号。
DLL_PUBLIC
(根据
GCC Visibility 维基)。 makefile 配方将使用如下内容:
$(PLUGIN): $(PLUG_OBJS) $(FRAME_OBJS) $(OUTPUT)
$(CXX) -shared -o $(OUTPUT) $(CXXFLAGS) $(PLUG_OBJS) $(FRAME_OBJS) $(BOOST_LIBS) $(LDFLAGS) -Wl,--exclude-libs,ALL
nm -gCD libplugin.so | grep ' T '
nm -gCD libplugin.so | grep ' T '
疣。我只是在 Binutils 邮件列表中寻找一种更好的方式来显示导出。
CPP = g++
CPP
是预处理器。使用
CXX
.
FLAGS = ...
CXXFLAGS
对于 C++ 项目。您的 C++ 配方可能如下所示:
SRCS = $(sort $(wildcard *.cpp))
OBJS = $(SRCS:.cpp=.o)
%.o : %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $<
关于c++ - 与共享库链接时 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52213253/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!