Undefined references: cygwin_posix_to_win32_path_list and cygwin_posix_to_win32_path_list_buf_size

StackOverflow https://stackoverflow.com/questions/23210522

  •  07-07-2023
  •  | 
  •  

Question

I am trying to compile a code in Cygwin and I am receiving undefined reference error for "cygwin_posix_to_win32_path_list" and "cygwin_posix_to_win32_path_list_buf_size".

Is there any missing library that I should add? I am sure that win32 api packages are installed.

Thank you for your help.

tclEnv.o:tclEnv.c:(.text+0xf6): undefined reference to `cygwin_posix_to_win32_path_list_buf_size'
tclEnv.o:tclEnv.c:(.text+0xf6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cygwin_posix_to_win32_path_list_buf_size'
tclEnv.o:tclEnv.c:(.text+0x118): undefined reference to `cygwin_posix_to_win32_path_list'
tclEnv.o:tclEnv.c:(.text+0x118): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cygwin_posix_to_win32_path_list'
/usr/bin/ld: tclEnv.o: bad reloc address 0x0 in section `.pdata'
collect2: error: ld returned 1 exit status
Makefile:550: recipe for target 'libtcl8.5.dll' failed
make: *** [libtcl8.5.dll] Error 1
Était-ce utile?

La solution

These functions were part of Cygwin 1.x, but were removed in Cygwin 2.x.

Therefore we have to make some utility functions that utilizes new functions from version 2, but keeps the same name and interface (an adapter). As I needed to use some code made in 2006 I also need to accomplish this. So let's start by looking at the documentation ...

This is the function definition for the current function for converting paths

ssize_t cygwin_conv_path( cygwin_conv_path_t what, const void * from, void * to, size_t size );

This is the function definition for the previous function for converting paths

void cygwin_posix_to_win32_path_list(const char *posix, char * win32);

Using this and the example (from the official docs), we can probably make something work.

/**
 * Adapter for old Cygwin 1.x functions missing from Cygwin 2.x
 *
 * Based on the documentation for 1.4 and 2.x
 * - http://pipeline.lbl.gov/code/3rd_party/licenses.win/cygwin-doc-1.4/html/cygwin-api/func-cygwin-posix-to-win32-path-list.html
 * - https://cygwin.com/cygwin-api/func-cygwin-conv-path.html
 *
 */
#include <sys/cygwin.h>

void cygwin_posix_to_win32_path_list(const char *posix, char * win32){

    // We do not know the size of the win32 buffer, but hopefully
    // it is at least size long ...
    ssize_t size = cygwin_conv_path( CCP_POSIX_TO_WIN_A, posix, NULL, 0);

    cygwin_conv_path( CCP_POSIX_TO_WIN_A, posix, win32, size);
}

There are many ways to use this to fix your code:

  • copy-paste into the code
  • save into adapter.c and #include adapter.c in the relevant code
  • compile it into adapter.o and link it to the other object files using ld
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top