如何使用-reduce-relocations构建QT

时间:2017-12-24 04:32:04

标签: c++ qt

我使用的是Ubuntu 16.04,cmake 3.10.1,QT 5.6.2 我以前在windows上开发应用程序,所以我不确定如何在linux平台上拍摄麻烦。

编译代码时,我收到错误

In file included from /usr/local/Qt/5.6.2/5.6/gcc_64/include/QtCore/qcoreapplication.h:37:0,
                 from /usr/local/Qt/5.6.2/5.6/gcc_64/include/QtWidgets/qapplication.h:37,
                 from /usr/local/Qt/5.6.2/5.6/gcc_64/include/QtWidgets/QApplication:1,
                 from /home/sulfred/Documents/SoftwareDev/github/SulfredLee/PcapReplayer/BackEnd/main.cpp:3:
/usr/local/Qt/5.6.2/5.6/gcc_64/include/QtCore/qglobal.h:1087:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
 #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
    ^

Q1。
如何验证我的Qt是使用-reduce-relocations构建的。

2 个答案:

答案 0 :(得分:1)

显然Qt已经用-reduce-relocations编译;错误消息指出您必须使用适当的标志构建自己的代码。相关:

Error while compiling QT project in cmake

https://github.com/wkhtmltopdf/qtbase/commit/36d6eb721e7d5997ade75e289d4088dc48678d0d

因此,只需尝试将-fPIE-fPIC标志添加到编译器标志中。

答案 1 :(得分:0)

在现代CMake中,使用target_compile_options()添加rng = pd.date_range('2019-01-01', periods=365, freq='D') df= pd.DataFrame({'Date': rng, 'Val': np.random.randint(50, 80, size=365), 'Node': 'A'}) df.set_index('Date', inplace=True) df1 = df[(df['Val']>=60)&(df['Val']<=70)] # We don't need to consider other values df1['Month'] = df1.index.month df2 = df1.groupby(['Month', 'Node']).agg({'Val':['max', 'count']}) df2.columns = df2.columns.droplevel() df2['count'] = np.where(df2['max']!=70, 0, df2['count']) # If it never gets to 70, assigning count as 0 df2 = df2.reset_index().drop('max', axis=1) df2 Month Node count 0 1 A 15 1 2 A 13 2 3 A 14 3 4 A 10 4 5 A 10 5 6 A 11 6 7 A 8 7 8 A 17 8 9 A 0 9 10 A 12 10 11 A 7 11 12 A 15 编译标志:

-fPIC

此外,Qt通常对add_executable(MyExecutable ...) target_compile_options(MyExecutable PRIVATE -fPIC) 不满意,但它需要fPIE。使用CMake变量CMAKE_POSITION_INDEPENDENT_CODE设置-fPIC仅适用于目标。此变量会将fPIC添加到可执行目标中,这对于Qt来说还不够。因此,请改用fPIE显式设置target_compile_options()