Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Linking error occurs when using hipcc compiling file #33

@mu910125

Description

@mu910125

hipamd branch: rocm-5.2.x
working directory: /workspace/
hipamd build command:

cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON /workspace/src//hipamd -B /workspace/build/Debug//hipamd -DHIP_COMMON_DIR=/workspace/src//HIP '-DCMAKE_PREFIX_PATH=/workspace/build/Debug//comgr;/workspace/build/Debug//llvm-project' -Dhsa-runtime64_DIR=/workspace/install/Debug/rocm/lib/cmake/hsa-runtime64 -DAMD_OPENCL_PATH=/workspace/src//ROCm-OpenCL-Runtime -DROCCLR_PATH=/workspace/src//ROCclr -DCMAKE_INSTALL_PREFIX=/workspace/install/Debug/rocm -DROCM_PATH=/workspace/install/Debug/rocm`

That building command executed outside the building_stage dir is leading to this issuse happen.↓↓

cmake --build /workspace/build/Debug//hipamd --target install

After hipcc building is completed, test hipcc function.

hipcc test file: main.c

#include "hip/hip_runtime.h"
int main()
{
	printf("[HIP]  %d\n", HIP_VERSION);
	return 0;
}

hipcc compile command:hipcc main.c
error output during compile test file:
/usr/bin/ld: /workspace/install/Debug/rocm/lib/libamdhip64.so: undefined reference to __hip_pch'
/usr/bin/ld: /workspace/install/Debug/rocm/lib/libamdhip64.so: undefined reference to __hip_pch_size

I found that the hip_pch.o would not be generated in correct CMAKE_BINARY_DIR when building hipcc executable.
The follow patch can fix this problem.
Pull Request Here

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f81296d3..1fbd355c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -181,7 +181,11 @@ if(__HIP_ENABLE_PCH)
     set(HIP_LLVM_ROOT "${LLVM_DIR}/../../..")
   endif()
 
-  execute_process(COMMAND sh -c "${HIP_COMMON_BIN_DIR}/hip_embed_pch.sh ${HIP_COMMON_INCLUDE_DIR} ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/include ${HIP_LLVM_ROOT}" COMMAND_ECHO STDERR RESULT_VARIABLE EMBED_PCH_RC)
+  execute_process(COMMAND sh -c "${HIP_COMMON_BIN_DIR}/hip_embed_pch.sh ${HIP_COMMON_INCLUDE_DIR} ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/include ${HIP_LLVM_ROOT}" 
+    COMMAND_ECHO STDERR 
+    RESULT_VARIABLE EMBED_PCH_RC 
+    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
+
   if (EMBED_PCH_RC AND NOT EMBED_PCH_RC EQUAL 0)
     message(FATAL_ERROR "Failed to embed PCH")
   endif()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions