You are not logged in.

#1 2021-09-13 16:18:12

followait
Banned
Registered: 2019-11-01
Posts: 58

[DUPLICATED] WARNING: Package contains reference to $srcdir

DUPLICATED

https://bbs.archlinux.org/viewtopic.php?id=239092

-------------------------

UPDATE 3

After a little digging, I've found __FILE__ in deeper included files e.g.

#include <cstdint>

include

#include <bits/c++config.h>

include

__FILE__

-------------------------

UPDATE 2

After debugging, the problem is clear now, but I don't know:

  • How to fix it?

  • Why does gcc make a footprint for this?

Among 7 similiar cpp files in the lib, paths of 3 of them are hard coded into `libBasicToolBox.so`, among the 3,  take MathUtil.cpp for example
BTW

strip --strip-all ./libBasicToolBox.so

hot help.

  1. $ strings /path/to/libBasicToolBox | grep -F MathUtil/MathUtil.cpp
    $srcdir/MathUtil/MthUtil.cpp
    $ readelf -s /path/to/libBasicToolBox.so
    (MathUtil.cpp can be found, but not in a full path)
  2. execlude MathUtil.cpp from the project and rebuid (in release)

  3. $ strings /path/to/libBasicToolBox | grep -F MathUtil/MathUtil.cpp
    (empty)

MathUtil.h and MathUtil.cpp are quite simple as below

MathUtil.h

#pragma once

#include <limits>
#include <vector>

#include <basictoolbox_export.h>

class BASICTOOLBOX_EXPORT MathUtil
{
public:
    MathUtil();
    ~MathUtil();
public:
    static bool StringToDouble(const char * p, double & result);
	inline static bool IsEqual(double a, double b) { return IsZero(a - b); }
    inline static bool IsZero(double n) { return n < std::numeric_limits<double>::epsilon() && n > -std::numeric_limits<double>::epsilon(); }
    inline static bool IsPositive(double n) { return n > std::numeric_limits<double>::epsilon(); }
    inline static bool IsNegative(double n) { return n < -std::numeric_limits<double>::epsilon(); }
    static double Log(double baseNum, double trueNum);
    static double GetRatio(double numerator, double denominator);
    static double GetGrowth(double latter, double former);
    static double StdDev(const std::vector<double> & values);
private:
    static inline bool IsDigit(char c)
    {
        return c >= 0x30 && c <= 0x39;
    }
};

MathUtil.cpp

#include <cmath>
#include <cstdint>

#include "MathUtil.h"

MathUtil::MathUtil()
{
}

MathUtil::~MathUtil()
{
}

bool MathUtil::StringToDouble(const char * p, double & result)
{
    result = 0.0;
    bool is_end = false;
    bool is_negtive = false;
    bool is_integral_part = true;
    int integral_part_digit_count = 0;
    int decimal_part_digit_count = 0;
    std::int64_t integral_part = 0;
    std::int64_t decimal_part = 0;
    while (true)
    {
        if (*p == '.')
            is_integral_part = false;
        else if (IsDigit(*p))
        {
            int n = (*p) - 0x30;
            if (is_integral_part)
            {
                ++integral_part_digit_count;
                integral_part = integral_part * 10 + n;
            }
            else
            {
                ++decimal_part_digit_count;
                decimal_part = decimal_part * 10 + n;
            }
        }
        else if (is_integral_part)
        {
            if (integral_part_digit_count == 0)
            {
                if (*p == '-')
                    is_negtive = true;
                else if (*p == '+')
                    is_negtive = false;
                else
                    is_end = true;
            }
            else if (*p != ',')
                is_end = true;
        }
        else
            is_end = true;

        if (is_end)
        {
            if (integral_part_digit_count + decimal_part_digit_count > 0)
            {
                if (decimal_part_digit_count > 0)
                    result = double(integral_part + decimal_part / pow(10, decimal_part_digit_count));
                else
                    result = double(integral_part);

                if (is_negtive)
                    result *= -1.0;

                return true;
            }
            else
                return false;
        }

        ++p;
    }

    return false;
}

double MathUtil::Log(double baseNum, double trueNum)
{
	assert(!(baseNum < std::numeric_limits<double>::epsilon()) &&
		   !(trueNum < std::numeric_limits<double>::epsilon()));

	return std::log(trueNum) / std::log(baseNum);
}

double MathUtil::GetRatio(double numerator, double denominator)
{
    if (IsZero(numerator))
    {
        return 0.0;
    }
    else if (IsZero(denominator))
    {
        if (numerator > 0.0)
            return std::numeric_limits<double>::infinity();
        else if (numerator < 0.0)
            return -std::numeric_limits<double>::infinity();
    }
    else if (denominator > 0.0)
    {
        return numerator / denominator;
    }
    else
    {
        wxASSERT(denominator < 0.0);

        if (numerator > 0.0)
            return std::numeric_limits<double>::infinity();
        else if (numerator < 0.0)
            return numerator / numerator * -1;
    }

    wxASSERT(false);
    return -1.0;
}

double MathUtil::GetGrowth(double latter, double former)
{
    if (!IsZero(former))
        return (latter - former) / std::abs(former);
    else
    {
        if (IsPositive(latter))
            return std::numeric_limits<double>::infinity();
        else if (IsNegative(latter))
            return -std::numeric_limits<double>::infinity();
        else
            return 0.0;
    }

    return 0.0;
}

double MathUtil::StdDev(const std::vector<double> & values)
{
    size_t count = values.size();
    if (count == 0)
        return 0.0;

    double sum = 0.0;
    for (const double n : values)
        sum += n;

    double avg = sum / count;

    double totalVariance = 0.0;
    for (const double n : values)
        totalVariance += std::pow(n - avg, 2);

    double stddev = std::sqrt( totalVariance / count);

    return stddev;
}

-------------------------

UPDATE 1

The ouput  of the command below shows that it libBasicToolBox.so contains paths to $srcdir, why and how to fix it?

strings ./pkg/basic-toolbox/usr/local/lib/libBasicToolBox.so | grep -F $srcdir

PS: It should be the value of $srcdir in PKGBULD here, use $srcdir for clarity.

-------------------------

pkgname=basic-toolbox
pkgver="1.0"
pkgrel=1
pkgdesc="C++ library for convenience"
arch=('x86_64')
provides=('basic-toolbox')
license=('MIT')
depends=('boost' 'curl' 'openssl' 'protobuf' 'sqlite' 'wxgtk3')
makedepends=('cmake>=3.20' 'git' 'openssl')
source=("$pkgname-$pkgver"::"git+ssh://path/to/basic_toolbox.git")
sha256sums=('SKIP')
install_prefix='/usr/local'

build() {
    cd "$pkgname-$pkgver"

    cmake -S . \
          -B out \
          -DCMAKE_BUILD_TYPE=Release \
          -DwxWidgets_CONFIG_EXECUTABLE='/usr/local/bin/wx-config-gtk3'

    cmake --build out
}

package() {
    cd "$pkgname-$pkgver"
    
    DESTDIR="$pkgdir" cmake --install out --prefix "/usr/local"
}
$ makepkg
...
==> WARNING: Package contains reference to $srcdir
usr/local/lib/libBasicToolBox.so
...

How to fix the warning?
BTW, after installing and deleting $srcdir, the installed lib works well.

CMakeLists.txt for BasicToolBox

cmake_minimum_required(VERSION 3.20)

project(BasicToolBox
        VERSION 1.0.10
        LANGUAGES CXX)

################
# cmake config #
################

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_TESTING "Build Tests" OFF)

##############
# dependency #
##############

find_package(Boost 1.76.0 REQUIRED COMPONENTS locale)
find_package(CURL REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Protobuf REQUIRED)
find_package(SQLite3 REQUIRED)
find_package(wxWidgets REQUIRED COMPONENTS base core)

##########
# target #
##########

include(cmake/collect_source_files.cmake)

add_library(${PROJECT_NAME} ${CPP_FILES})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

# export macro
include(GenerateExportHeader)
generate_export_header(${PROJECT_NAME})

target_precompile_headers(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/BasicToolBox/pch/pch.h)

include(GNUInstallDirs)

target_include_directories(${PROJECT_NAME}
                           PUBLIC # use PUBLIC instead of PRIVATE because tests use it
                               $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
                               $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
                           INTERFACE
                               $<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}>
                               $<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}/export>)

target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost)

target_link_libraries(${PROJECT_NAME} PUBLIC CURL::libcurl)

target_link_libraries(${PROJECT_NAME} PUBLIC OpenSSL::Crypto)

target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf)

target_link_libraries(${PROJECT_NAME} PUBLIC SQLite::SQLite3)

include(${wxWidgets_USE_FILE})
#target_include_directories(${PROJECT_NAME} PUBLIC ${wxWidgets_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${wxWidgets_LIBRARIES})

########
# test #
########

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
    if(BUILD_TESTING)
        include(CTest)
        enable_testing()
        include(Test/Test.cmake)
    endif()
endif()

###########
# install #
###########

install(TARGETS ${PROJECT_NAME}
        EXPORT ${PROJECT_NAME})
install(EXPORT ${PROJECT_NAME}
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
        NAMESPACE BasicToolBox::
        FILE ${PROJECT_NAME}Config.cmake)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/BasicToolBox" # source directory
        DESTINATION "include" # target directory
        FILES_MATCHING
        PATTERN "*.h" # install only matched files
        PATTERN "pch" EXCLUDE) # exclude pch

string(TOLOWER ${PROJECT_NAME}_export.h EXPORT_FILE_NAME)
install(FILES ${CMAKE_BINARY_DIR}/${EXPORT_FILE_NAME}
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/export)

Last edited by followait (2021-09-14 09:45:02)

Offline

#2 2021-09-13 17:18:16

mpan
Member
Registered: 2012-08-01
Posts: 718
Website

Re: [DUPLICATED] WARNING: Package contains reference to $srcdir

There is no general answer to that. There may be many reasons that path is present in the finished package. Not knowing, what software that is, makes answering the question even harder to people here.

Since it’s found in a library, it is likely unstripped debugging information or an expansion of __FILE__.

If the above is true, the situation is benign for operation of this piece of software. It is not reproducible (which is bad) and there may be privacy implications if distributed, but it will work. However, there are also some other causes possible, which may break the program too. For example if somehow that path ended up as a hardcoded path to something software will try to use at runtine.


Sometimes I seem a bit harsh — don’t get offended too easily! PGP: 7C848198AE93D3BB

Offline

#3 2021-09-13 17:21:29

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,718
Website

Re: [DUPLICATED] WARNING: Package contains reference to $srcdir

This is generally harmless.  "Fixing" it also generally requires patching the upstream code.

Both of these are just "generally" though as you've obscured the actual source so we can't check.  Is this a project you intend to share on the AUR or is it just for your own use?  Are you the author also of the "upstream" source?  Or where is it from?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2021-09-14 02:10:20

followait
Banned
Registered: 2019-11-01
Posts: 58

Re: [DUPLICATED] WARNING: Package contains reference to $srcdir

mpan wrote:

Since it’s found in a library, it is likely unstripped debugging information or an expansion of __FILE__.

If the above is true, the situation is benign for operation of this piece of software. It is not reproducible (which is bad) and there may be privacy implications if distributed, but it will work. However, there are also some other causes possible, which may break the program too. For example if somehow that path ended up as a hardcoded path to something software will try to use at runtine.

Trilby wrote:

This is generally harmless.  "Fixing" it also generally requires patching the upstream code.

Both of these are just "generally" though as you've obscured the actual source so we can't check.  Is this a project you intend to share on the AUR or is it just for your own use?  Are you the author also of the "upstream" source?  Or where is it from?

I'm the author of the upstream source.
makepkg strips the release binary.
Nothing like __FILE__ in the source codes.
In fact, the lib has only very basic implementations, not referencing source paths.
Anyway I'll comment some codes to debug it.

Thanks

Offline

#5 2021-09-15 20:18:58

mpan
Member
Registered: 2012-08-01
Posts: 718
Website

Re: [DUPLICATED] WARNING: Package contains reference to $srcdir

For the record, if anyone following this topic is confused or someone wants to repeat the OP’s mistakes. EOT


Sometimes I seem a bit harsh — don’t get offended too easily! PGP: 7C848198AE93D3BB

Offline

Board footer

Powered by FluxBB