In Eclipse, I am getting a post build error when I convert my C elf file into an IMG file.
This is the error:
Building target: USBDebug.elf
Invoking: ARM Sourcery Windows GCC C Linker
arm-none-eabi-gcc ./cyfx_gcc_startup.o ./cyfxtx.o ./cyfxusbdebug.o ./cyfxusbdscr.o -T"C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.2\/firmware/common/fx3.ld" -nostartfiles -Wl,-Map,USBDebug.map -Wl,-d -Wl,--no-wchar-size-warning -Wl,--gc-sections -Wl,--entry,CyU3PFirmwareEntry "C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.2\\firmware\u3p_firmware\lib\fx3_debug\cyfxapi.a" "C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.2\\firmware\u3p_firmware\lib\fx3_debug\cyu3lpp.a" "C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.2\\firmware\u3p_firmware\lib\fx3_debug\cyu3threadx.a" "C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.2\\arm-none-eabi\lib\libc.a" "C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.2\\lib\gcc\arm-none-eabi\4.5.2\libgcc.a" -mcpu=arm926ej-s -mthumb-interwork -g -gdwarf-2 -o"USBDebug.elf"
**/usr/bin/sh: C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.2\util\elf2img\elf2img.exe: command not found
Finished building target: USBDebug.elf
cs-make[1]: [post-build] Error 127 (ignored)**
cs-make --no-print-directory post-build
Converting ELF to image (.img) format
"C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.2\\util\elf2img\elf2img.exe" -i USBDebug.elf -o USBDebug.img
It seems odd to me that /usr/bin/sh appears even though I am in windows. I can go into the command prompt and type this in and it works perfectly
"C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.2\\util\elf2img\elf2img.exe" -i USBDebug.elf -o USBDebug.img
Would anybody know why I am getting command not found?
The problem is that the spaces and parentheses in your path are not escaped correctly.
I was able to fix this on my setup by going to "C/C++ Build" -> "Settings" -> "Build Steps"
and changing the double quotes (") in the command to single quotes (').
More information about this problem can be found here http://www.cypress.com/?app=forum&id=167&rID=78767
Related
This question already has answers here:
CMake link to external library
(6 answers)
Closed 2 years ago.
I created a dynamic lib using Rust (crate type = "cdylib"). Rust/Cargo produced two files: text_loading_lib.dll and text_loading_lib.dll.lib. I want to build a really simple project (hello_world.c) on Windows that uses a function from this lib using only MSVC (the Microsoft Visual C++ toolset) and JetBrains CLion/CMake.
main.c
#include <stdio.h>
typedef unsigned long long usize_t; // 64 bit / usize on 64 bit machine
extern void show_loading_animation_ffi(usize_t, usize_t, int, usize_t (*prog_fn)());
// function that tells the lib how many percent progress we made so far
usize_t progress_reporter() { return (usize_t) 20 }
int main(void) {
show_loading_animation_ffi(0, 100, TARGET_STDERR, progress_reporter);
return 0;
}
I'm familiar with this process on UNIX, but I have no clue how it is done on Windows. On UNIX, I'd link the shared object against main.c during compilation and provide its location using LD_LIBRARY_PATH at runtime. Is is similar on Windows?
I also tried it with a CMAKE project using JetBrains CLion, but still no success. When I try to run main() in main.c from CLion, there are always errors that the target can't be created. The library files created with Rust (text_loading_lib.dll and text_loading_lib.dll.lib) are in the same directory as CMakeLists.txt and main.c.
CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(main C)
set(CMAKE_C_STANDARD 11)
add_executable(main main.c)
# the path is correct
target_link_libraries(main text_loading_animation)
#also tried: target_link_libraries(main text_loading_animation.dll)
#also tried: target_link_libraries(main text_loading_animation.dll.lib)
CLion-Output is:
[ 50%] Linking C executable main.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1426~1.288\bin\Hostx64\x64\link.exe /nologo #CMakeFiles\main.dir\objects1.rsp /out:main.exe /implib:main.lib /pdb:C:\dev\lib-text-loading-animation-rust\calling-from-c-examples\windows\cmake-build-debug\main.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console text_loading_animation.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\main.dir/intermediate.manifest CMakeFiles\main.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: File "text_loading_animation.lib" can't be opened.
NMAKE : fatal error U1077: ""C:\Program Files\JetBrains\CLion 2020.1.1\bin\cmake\win\bin\cmake.exe"": Return-Code "0xffffffff"
Stop.
NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\nmake.exe"": Rückgabe-Code "0x2"
Stop.
NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\nmake.exe"": Rückgabe-Code "0x2"
Stop.
NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\nmake.exe"": Rückgabe-Code "0x2"
Stop.
I got it working with CMake as well as the Command Line.
Cmake: CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(main C)
set(CMAKE_C_STANDARD 11)
add_executable(main main.c)
# "*.dll.lib" - important! not just *.dll
target_link_libraries(main ${CMAKE_CURRENT_SOURCE_DIR}/../../target/release/text_loading_animation.dll.lib)
# copy DLL file into target dir
add_custom_command(TARGET main POST_BUILD # Adds a post-build event to "main"
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..."
"${PROJECT_SOURCE_DIR}/text_loading_animation.dll" # <--this is in-file
$<TARGET_FILE_DIR:main>) # <--this is out-file path
Now you can "run main" in Jetbrains CLion for example.
Command Line (windows batch script)
Important part is:
cl main.c /link text_loading_animation.dll.lib
main.exe
Full Batch script:
#echo off
rem: clean old data
del main.exe main.obj *.dll *.dll.lib
rem: copy rust lib into current dir
xcopy /y ..\..\target\release\text_loading_animation.dll .
xcopy /y ..\..\target\release\text_loading_animation.dll.lib .
rem: sets up Visual Studio Compilertoolsuite environment
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
rem: *.dll.lib contains header information during compile; *.dll is the runtime file that must be in the same directory/path
rem: "cl" is windows compiler: produces main.obj and main.exe; main.obj is not needed in the end;
rem: it is only for the stage between compiling and linking
rem: /W4 is highest warnings flag
cl /W4 main.c /link text_loading_animation.dll.lib
del main.obj
rem: now execute
main.exe
I generated a project by the STMCubeMX and wanted to import this project into Clion.
Here's the CmakeList.txt:
project(ClionTest)
cmake_minimum_required(VERSION 3.8)
add_definitions(-DSTM32F4xx)
file(GLOB_RECURSE USER_SOURCES "Src/*.c")
file(GLOB_RECURSE HAL_SOURCES "Drivers/STM32F4xx_HAL_Driver/Src/*.c")
add_library(CMSIS
startup/startup_stm32f407xx.s)
include_directories(Drivers/CMSIS/Device)
include_directories(Drivers/CMSIS/Device/ST/STM32F4xx/Include)
include_directories(Drivers/CMSIS/Include)
include_directories(Drivers/STM32F4xx_HAL_Driver)
include_directories(Drivers/STM32F4xx_HAL_Driver/Inc)
include_directories(Inc)
include_directories(Middlewares/Third_Party/LwIP/src/include)
add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${HAL_SOURCES} ${LINKER_SCRIPT})
target_link_libraries(${PROJECT_NAME}.elf CMSIS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")
And a STM32F4xx.cmake file:
INCLUDE(CMakeForceCompiler)
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
#CMAKE_FORCE_C_COMPILER(C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q2-update/bin/arm-none-eabi-gcc.exe GNU)
#CMAKE_FORCE_CXX_COMPILER(D:/Lib/arm/bin/arm-none-eabi-g++.exe GNU)
SET(CMAKE_C_COMPILER "C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q2-update/bin/arm-none-eabi-gcc.exe")
SET(CMAKE_CXX_COMPILER "C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q2-update/bin/arm-none-eabi-g++.exe")
SET(LINKER_SCRIPT ${PROJECT_SOURCE_DIR}/STM32F407VETx_FLASH.ld)
#Uncomment for software floating point
#SET(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=soft -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
SET(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
SET(CMAKE_CXX_FLAGS_INIT "${COMMON_FLAGS} -std=c++11")
SET(CMAKE_C_FLAGS_INIT "${COMMON_FLAGS} -std=gnu99")
SET(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-gc-sections,-M=binary.map -T ${LINKER_SCRIPT}")
I set LINKER_SCRIPT ${PROJECT_SOURCE_DIR}/STM32F407VETx_FLASH.ld
File structure
And the Cmake options is:
Cmake options
When I reload this project, it's not go on well.
c:/progra~2/gnutoo~1/62017-~1/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/bin/ld.exe: cannot open linker script file
D:/Project/ClionTest/cmake-build-default/CMakeFiles/CMakeTmp/STM32F407VETx_FLASH.ld:
Invalid argument
collect2.exe: error: ld returned 1 exit status
CMakeFiles\cmTC_bf7b4.dir\build.make:96: recipe for target 'cmTC_bf7b4' failed
mingw32-make.exe[1]: *** [cmTC_bf7b4] Error 1
mingw32-make.exe[1]: Leaving directory
'D:/Project/ClionTest/cmake-build-default/CMakeFiles/CMakeTmp'
Makefile:125: recipe for target 'cmTC_bf7b4/fast' failed
mingw32-make.exe: *** [cmTC_bf7b4/fast] Error 2
It seems like the path of ld.exe is not correct,how shoulld I set its path?
And why the path of STM32F407VETx_FLASH.ld it searched is not the path I set?
I'm using Linux, but I've had the a similar issue in regards to being unable to open the linker script.
cannot open linker script file D:/Project/ClionTest/cmake-build-default/CMakeFiles/CMakeTmp/STM32F407VETx_FLASH.ld
After looking for a while at the documentation for target_link_option (which does approximately the same kind of thing as setting a variable directly), I took note of the SHELL: directive, that's stated to:
The set of options is de-duplicated to avoid repetition. While beneficial for individual options, the de-duplication step can break up option groups. For example, -D A -D B becomes -D A B. One may specify a group of options using shell-like quoting along with a SHELL: prefix. The SHELL: prefix is dropped and the rest of the option string is parsed using the separate_arguments() UNIX_COMMAND mode.
By adding it to my command, I managed to get compilation working normally. The result was the following:
set(LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/STM32F303CCTX_FLASH.ld")
set(LINKER_FLAGS "SHELL:-T${LINKER_SCRIPT} -Wl,--gc-sections --specs=nano.specs --specs=nosys.specs")
target_link_options(${PROJECT_BINARY} PRIVATE ${LINKER_FLAGS})
Change this:
SET(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-gc-sections,-M=binary.map -T ${LINKER_SCRIPT}")
To:
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections,-M=binary.map -T${LINKER_SCRIPT}")
I'm using ATMEL Studio 6.2 and its toolchain with avr-gcc (avr8-gnu-toolchain). I have a variable that needs to be placed in flash (PROGMEM) and I declare it as a global:
static const uint16_t gPrgLen PROGMEM __attribute__((used)) = 0;
The compiler doesn't complain and the linker doesn't complain, but when I open the .lss file, there is no gPrgLen to be found. In the .map file we can see that it has been listed under "discarded input sections"
Discarded input sections
.progmem.data.gPrgLen 0x00000000 0x2 Boot.o
It is built as a release, but a debug build gives the same result.
How can I force the linker to include this variable in the *(.progmem*) section?
EDIT
Added static but still the same result.
Here is the linker part:
# All Target
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)
$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP)
#echo Building target: $#
#echo Invoking: AVR/GNU Linker : 4.8.1
$(QUOTE)C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="Boot.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -Wl,-section-start=.text=0xf800 -mmcu=at90usb647
#echo Finished building target: $#
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "Boot.elf" "Boot.hex"
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "Boot.elf" "Boot.eep" || exit 0
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "Boot.elf" > "Boot.lss"
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "Boot.elf" "Boot.srec"
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-size.exe" "Boot.elf"
Odd that __attribute__((used)) isn't working. Two suggestions to try.
First, change the variable from static to volatile (or just add volatile). That may prevent it from being optimized away.
If that doesn't work, instead you can add a line to the linker to make it "[p]retend the symbol symbol is undefined, to force linking of library modules to define it" (GCC Link Options). This is done via -u symbol or --undefined=symbol.
To add it to the Atmel Studio project file, go to Toolchain -> AVR/GNU Linker -> Miscellaneous. Then in Other Linker Flags add --undefined=gPrgLen.
I've used this to embed revision/compile-time information into the Hex file where it wasn't otherwise used. That way I could retrieve the memory from a device and know under what conditions it was built (primarily for tracking changes during prototyping and initial firmware debugging). My main.c file had a global char array that looked something like const char codeCompileDetails[] PROGMEM = "company_name-" __DATE__ "-" __TIME__;. Coupled with --undefined=codeCompileDetails, that data (here including the date and time the code was compiled) always makes it into the executable.
I downloaded freeRTOS Basic Example -EVK1100 from the example Gallery provided by Atmel Studio and try to build it, i got this error
recipe for target 'src/asf/avr32/utils/startup/trampoline_uc3.o' failed
the Build output gives :
Building file: ../src/asf/avr32/utils/startup/trampoline_uc3.s
Invoking: AVR32/GNU Assembler : 4.4.7
C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr32\avr32-gnu-toolchain\bin\avr32-as.exe: unrecognized option `-mrelax'
make: *** [src/asf/avr32/utils/startup/trampoline_uc3.o] Error 1
"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr32\avr32-gnu-toolchain\bin\avr32-as.exe" -mpart=uc3a0512 -mrelax -I "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\UC3A_DFP\1.0.53\include\AT32UC3A0512" -I "../thirdparty/freertos/demo/avr32_uc3_example/at32uc3a0512_evk1105" -I "../src/ASF/avr32/utils" -I "../src/config" -I "../src/ASF/avr32/boards/evk1105" -I "../src/ASF/thirdparty/freertos/demo/common/include" -I "../src/ASF/common/utils" -I "../src" -I "../src/ASF/avr32/boards" -I "../src/ASF/thirdparty/freertos/demo/avr32_uc3_example" -I "../src/ASF/avr32/drivers/tc" -I "../src/ASF/avr32/drivers/gpio" -I "../src/ASF/thirdparty/freertos/freertos-7.0.0/source/include" -I "../src/ASF/common/boards" -I "../src/ASF/thirdparty/freertos/demo/avr32_uc3_example/at32uc3a0512_evk1105" -I "../src/ASF/avr32/utils/preprocessor" -I "../src/ASF/avr32/drivers/intc" -I "../src/ASF/thirdparty/freertos/freertos-7.0.0/source/portable/gcc/avr32_uc3" -I "../src/ASF/avr32/drivers/pm" -I "../src/ASF/avr32/drivers/usart" -I "../src/ASF/avr32/drivers/flashc" -g -o "src/asf/avr32/utils/startup/trampoline_uc3.o" "../src/asf/avr32/utils/startup/trampoline_uc3.s"
C:\Users\xxx\Documents\Atmel Studio\7.0\FREERTOS_UC3_EXAMPLE2\FREERTOS_UC3_EXAMPLE2\Debug\Makefile(518,1): error: recipe for target 'src/asf/avr32/utils/startup/trampoline_uc3.o' failed
I believe that the linker complains about the option -mrelax`unrecognized option -mrelax.
This reference shows that i have to check relax branches, but i can't find the option in my version
I wonder if there is a patch to apply to my linker so it can recognize this option or to check/uncheck some options in the project file or ....
I'am using
Atmel Studio 7 (version 7.0.934)
Windows 10
Thanks in advance
The example project is built successfully after upgrading Atmel Studio to the last version.
To get the latest version :
help > check for updates
when I am running this .bat file on command prompt it is throwing an error i.e "The filename, directory name or volume label syntax is incorrect".
Batch file contains--
nmake /nologo /f makefile /a
pause
makefile contains the following:
# nmake makefile to build a sample ADK MAC compliant application
# NOTE: EOSSDK is needed to resolve ADK Library references and header file includes
VRXSDK = C:\eVoAps\SDK\1.2.0\VRXSDK
#VXEOS = C:\eVoAps\EOSSDK\2.1.4
ADK = C:\eVoAps\ADK
VSFSTOOL = C:\Program Files\VERIFONE\FST
VRXIncludes = $(VRXSDK)\include
ADKIncludes = $(ADK)\VRX\Include
EOSIncludes = $(EOSSDKNEW)\include\ssl2
IncDir = .\Source
SrcDir = .\Source
ObjDir = .\Objects
OutDir = .\Download
EOSObjects = C:\eVoAps\SDK\1.2.0\EOSSDKNEW\lib
Includes = -I$(IncDir) -I$(VRXIncludes) -I$(EOSIncludes) -I$(ADKIncludes) -I$(SrcDir)
# Compiler options
# Ignoring warning 1295 - Deprecated declaration - give arg types
# Defiing _VRXEVO for Verix specific code in the sample.
COptions = -vsoapp -g -p -armcc,"--diag_suppress 1295" -D _VRXEVO -DLOGAPI_ENABLE_DEBUG -DVFI_GUIPRT_IMPORT -DVFI_MAC_DLL_IMPORT -DVFI_IPC_DLL_IMPORT -DVFI_SYSINFO_DLL_IMPORT -DVFI_SYSBAR_DLL_IMPORT
LinkOptions = -vsoapp -g -p
# NOTE: elog.o required to resolve references in the ADK libs. Log lib requires STL
# LibVFIMac only needed to resolve sysShowDesktop()
# svc_net.o required for mac library....
Libs = $(ADK)\vrx\lib\libvfiguiprt.so \
$(ADK)\vrx\lib\libvfiipc.so \
$(ADK)\vrx\lib\liblog.so\
$(ADK)\vrx\lib\libvfimac.so \
$(VRXSDK)\lib\vxstl.so \
$(EOSSDKNEW)\lib\svc_net.o \
$(EOSSDKNEW)\lib\elog.o
AppObjects = $(ObjDir)\BossApp.o
$(OutDir)\BossApp.vsa.p7s : $(OutDir)\BossApp.vsa
"$(VSFSTOOL)\FST" BossApp.fst
$(OutDir)\BossApp.vsa : $(AppObjects)
$(VRXSDK)\bin\vrxcc $(AppObjects) $(Libs) -o $#
$(VRXSDK)\bin\vrxhdr -s 128000 -h 128000 -l ELOG.LIB=N:/ELOG.LIB -l NET.LIB=N:/NET.LIB
$(OutDir)\BossApp.vsa
###### Compile #######
$(ObjDir)\BossApp.o : $(SrcDir)\BossApp.cpp
$(VRXSDK)\bin\vrxcc -c $(Includes) $(COptions) -o $(ObjDir)\BossApp.o $(SrcDir)\BossApp.cpp
I am unable to figure out what i'm missing here.Please help me.
This will likely be the reason for a very low % of people but I was getting this error from any .BAT file on my machine (happened to be Windows Server 2019). In my case I was getting the error because I had recently installed ConEmu (console replacement app) and had it set for Integration mode (where it replaces the normal CMD app) and it was failing to launch .BAT files correctly. Once I turned off Integration mode for ConEmu my .BAT files started working again.
This procedure is not written in windows batch. It needs to be written in windows batch language to be processed by cmd.exe.