cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
6,376 Views
Registered: ‎08-21-2016

undefined reference to function in subdirectories (C-Sim

I am trying to compile a C-Project, which has lots of source files in different subfolders:

 

  • ...
  • hls_proj
  • main.c
  • header1.h
  • header2.h
  • subdir1
    • --source.c
  •  subdir2
    • --source.c
  • ...

I tried to put all subfolder and also header files in the testbench, but I get the following error:

 

Starting C simulation ...
/opt/Xilinx16/Vivado_HLS/2015.4/bin/vivado_hls /home/user/Desktop/HLS/hls_test/solution1/csim.tcl
@I [HLS-10] Running '/opt/Xilinx16/Vivado_HLS/2015.4/bin/unwrapped/lnx64.o/vivado_hls'
            for user 'user' on host '...' (Linux_x86_64 version 4.4.0-34-generic) on Sun Aug 21 21:51:47 CEST 2016
            in directory '/home/user/Desktop/HLS'
@I [HLS-10] Opening project '/home/user/Desktop/HLS/hls_test'.
@I [HLS-10] Opening solution '/home/user/Desktop/HLS/hls_test/solution1'.
@I [SYN-201] Setting up clock 'default' with a period of 10ns.
@I [HLS-10] Setting target device to 'xc7z020clg484-1'
   Generating csim.exe
Makefile.rules:349: recipe for target 'csim.exe' failed
obj/main.o: In function `main':
/tmp/apcc_db_user/183101471808943590764/main.c:696: undefined reference to `merge_arrays'
/tmp/apcc_db_user/183101471808943590764/main.c:768: undefined reference to `print_array_bytes'
collect2: ld returned 1 exit status
make: *** [csim.exe] Error 1
@E [SIM-1] 'csim_design' failed: compilation error(s).
4
    while executing
"source /home/user/Desktop/HLS/hls_test/solution1/csim.tcl"
    invoked from within
"hls::main /home/user/Desktop/HLS/hls_test/solution1/csim.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 hls::main {*}$args"
    (procedure "hls_proc" line 5)
    invoked from within
"hls_proc $argv"

 

I tried:

  • adding everything (files and directories) to the test bench
  • including the directories via cflags of main.c
  • including the directories ans also the c-files in the subdirectories via compiler setting in project properties
  • adding the header files to the Source
  • and lots recommendations found on the web, which somehow related to my problem

The only way to get the code compiled is to add  all of the source files to source or to the test bench in HLS, but it doesn't help me because there are many c-files in my project, which are in different folders, but have the same name, for example "subdir1/init.c" and "subdir/init.c"

 

 

0 Kudos
8 Replies
Highlighted
Teacher
Teacher
6,365 Views
Registered: ‎03-31-2012

Re: undefined reference to function in subdirectories (C-Sim

your problem is with linking so you need to add some -L options to your project to point to different .o files or directories in which which they reside.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
6,347 Views
Registered: ‎08-01-2008

Re: undefined reference to function in subdirectories (C-Sim

This issue is related to the Operating System and has been highlighted in various online forums.

The tested solution is:

1. Go to the link: http://support.code-red-tech.com/CodeRedWiki/VirtualAllocPointerNull and download the msys-1.0.dll file (the downloaded zip file is attached)

2. Now, go to the directory <Vivado_HLS_Home>\msys\bin and look for the file msys-1.0.dll file. Rename it to msys-1.0_old.dll.

3. Copy over the downloaded .dll file to the location specified in Step 2.

4. Open a command prompt and browse to the directory <Vivado_HLS_Home>\msys\bin and type sh.exe. It should take you to the shell :

C:\Xilinx\Vivado_HLS\2013.2\msys\bin>sh.exe
sh.exe-3.1$

5. Now, open Vivado HLS and run csim or RTL cosim without any cygwin errors.

Other solutions include:

1. Rebooting the system after installing the tool.
1. Disabling the Anti-Virus temporarily.
2. Add the executable <Vivado_HLS_Home>\msys\bin\sh.exe to the exceptions in your Antivirus.
3. Increase the Virtual Memory of your machine.
Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
0 Kudos
Highlighted
Visitor
Visitor
6,337 Views
Registered: ‎08-21-2016

Re: undefined reference to function in subdirectories (C-Sim

The problem is, that the .o are not built:

 

subdirProb.png

0 Kudos
Highlighted
Visitor
Visitor
6,335 Views
Registered: ‎08-21-2016

Re: undefined reference to function in subdirectories (C-Sim

This solution seems to be for Window, but I am working on Linux based System.
0 Kudos
Highlighted
Visitor
Visitor
6,275 Views
Registered: ‎08-21-2016

Re: undefined reference to function in subdirectories (C-Sim

It would be very nice if anybody from Xilinx staff could answer the question, if it is possible to use subdirectories in HLS at all.

 

 

0 Kudos
Highlighted
Moderator
Moderator
6,235 Views
Registered: ‎04-17-2011

Re: undefined reference to function in subdirectories (C-Sim

Different directories can be used but they have to be properly Included using the C-flag options. As you have tried that already, are you able to see the folder listed under the Include tab in HLS? If it is present then the files should get picked.
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
0 Kudos
Highlighted
Visitor
Visitor
6,164 Views
Registered: ‎08-21-2016

Re: undefined reference to function in subdirectories (C-Sim

The directories are shown in the include tree in  the explorer tab, but the source files are found.

Here is the content of script.tcl

############################################################
## This file is generated automatically by Vivado HLS.
## Please DO NOT edit it.
## Copyright (C) 2015 Xilinx Inc. All rights reserved.
############################################################
open_project hls_test
add_files -tb main.c -cflags "-Iprint_array -Imerge_array"
open_solution "solution1"
set_part {xc7z020clg484-1}
create_clock -period 10 -name default
#source "./hls_test/solution1/directives.tcl"
csim_design -clean
csynth_design
cosim_design
export_design -format ip_catalog

0 Kudos
Highlighted
Adventurer
Adventurer
5,680 Views
Registered: ‎12-03-2015

Re: undefined reference to function in subdirectories (C-Sim

If you open Project Settings -> Simulation Settings, do you see merge_array.c and print_array.c? If not then the files are not being added correctly. You could try "Adding File..." for each source file (painful but might be the only way). 

I have been able to add an entire directory and subdirectories but they only contained templated C++ header files, no cpp source code. It compiled fine. The lines from my script.tcl:

 

add_files -tb main-testbench.cpp
add_files -tb ../../../../o2linux64/Libs/Eigen/3.2.5/include/eigen3/Eigen
open_solution "calibrate1"
set_part {xc7z045ffg676-2}
0 Kudos