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

Linking error occurs when using hipcc compiling file #33

Open
mu910125 opened this issue Jul 9, 2022 · 0 comments
Open

Linking error occurs when using hipcc compiling file #33

mu910125 opened this issue Jul 9, 2022 · 0 comments

Comments

@mu910125
Copy link

mu910125 commented Jul 9, 2022

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()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant