2

I'm trying to use MSVC to compile a C program with the Flite text-to-speech library, but I'm getting unresolved external symbol errors.

I started with the "C Example" from the Flite docs but they use gcc. I was able to get rid of some errors by linking ws2_32.lib and legacy_stdio_definitions.lib but I can't find a solution to the remaining ones.

Do I just need to use a different compiler, or is there some solution that will allow me to use MSVC?

main.c

#include "flite.h"

register_cmu_us_kal();

int main(int argc, char **argv)
{
    cst_voice *v;

    if (argc != 2)
    {
        fprintf(stderr, "usage: flite_test FILE\n");
        exit(-1);
    }

    flite_init();

    v = register_cmu_us_kal(NULL);

    flite_file_to_speech(argv[1], v, "play");
}

build.bat

cl ..\src\main.c -I "../lib/Flite/include/" /link ws2_32.lib legacy_stdio_definitions.lib /LIBPATH:"../lib/Flite/lib" libflite_cmu_us_kal.a libflite_usenglish.a libflite_cmulex.a libflite.a

Result

build.bat
Microsoft (R) C/C++ Optimizing Compiler Version 19.13.26128 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

main.c
..\src\main.c(17): warning C4047: '=': 'cst_voice *' differs in levels of indirection from 'int'
Microsoft (R) Incremental Linker Version 14.13.26128.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe 
ws2_32.lib 
legacy_stdio_definitions.lib 
/LIBPATH:../lib/Flite/lib 
libflite_cmu_us_kal.a 
libflite_usenglish.a 
libflite_cmulex.a 
libflite.a 
main.obj 
libflite_usenglish.a(us_expand.o) : error LNK2019: unresolved external symbol __locale_ctype_ptr referenced in function en_exp_letters
libflite.a(cst_string.o) : error LNK2001: unresolved external symbol __locale_ctype_ptr
libflite.a(regexp.o) : error LNK2001: unresolved external symbol __locale_ctype_ptr
libflite.a(cst_lexicon.o) : error LNK2019: unresolved external symbol __getreent referenced in function cst_lex_make_entry
libflite.a(cst_error.o) : error LNK2001: unresolved external symbol __getreent
libflite.a(cst_tokenstream.o) : error LNK2001: unresolved external symbol __getreent
libflite.a(cst_mmap_posix.o) : error LNK2019: unresolved external symbol getpagesize referenced in function cst_mmap_file
libflite.a(cst_mmap_posix.o) : error LNK2019: unresolved external symbol mmap referenced in function cst_mmap_file
libflite.a(cst_mmap_posix.o) : error LNK2019: unresolved external symbol munmap referenced in function cst_munmap_file
libflite.a(au_oss.o) : error LNK2019: unresolved external symbol ioctl referenced in function audio_open_oss
main.exe : fatal error LNK1120: 6 unresolved externals

1 Answers1

0

I try to build GMP library using Cygwin64. When I try to use GMP library which I built I got the same error as follows

Rebuild started...
1>Source.cpp
1>D:\FromE\Daniel\VC++\Coursera\gmp-6.2.1_x64\gmp-6.2.1\gmp.h(1785,19): warning C4244: 'return': conversion from 'mp_limb_t' to 'unsigned long', possible loss of data
1>D:\FromE\Daniel\VC++\Coursera\MITMAFHLinkedIn\Source.cpp(113,1): warning C4326: return type of 'main' should be 'int' instead of 'void'
1>D:\FromE\Daniel\VC++\Coursera\MITMAFHLinkedIn\Source.cpp(186,28): warning C4244: 'initializing': conversion from '__int64' to 'unsigned long', possible loss of data
1>libgmp.a(memory.o) : error LNK2019: unresolved external symbol __getreent referenced in function __gmp_default_allocate
1>libgmp.a(realloc.o) : error LNK2001: unresolved external symbol __getreent
1>libgmp.a(n_pow_ui.o) : error LNK2001: unresolved external symbol __getreent
1>libgmp.a(assert.o) : error LNK2001: unresolved external symbol __getreent
1>libgmp.a(lt43-set_str.o) : error LNK2019: unresolved external symbol __locale_ctype_ptr referenced in function __gmpz_set_str
1>D:\FromE\Daniel\VC++\Coursera\MITMAFHLinkedIn\x64\Debug\MITMAFHLinkedIn.exe : fatal error LNK1120: 2 unresolved externals
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(1074,5): error MSB6006: "link.exe" exited with code 1120.
1>Done building project "MITMAFHLinkedIn.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

I tried to include

#pragma comment(lib, "libcygwin.a")

And the problem was resolved. If you use Mingw32 then try to include

#pragma comment(lib, "libgcc.a")
Ramnath
  • 11
  • 2