Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

system command in fortran dll

mi-she
Beginner
1,547 Views

I have created a dll using f90 code in Visual Studio (x64) that uses the 'system' command to determine the timestamp of a file.

rcode=system("dir "//trim(directory)//trim(fileid)//" > ts_scratch.txt")

The command is actually made in a subroutine called from within the code. When I tried to debug the dll by calling it in a main f90 program, the main program compiles, but the following error occurs when I run the executable:

The application failed to initialize properly (0xc00000142). Click on OK to terminate the application.

I am not sure what I have done incorrectly. Does anyone have an idea? (I am new to this forum and fairly new to fortran programming, so please let me know if I have left out any important information about this scenario.) Thanks!

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,547 Views

That looks ok. It's strange that Dependency Walker found many X86 DLLs - it shouldn't have. Something is wrong on your system.

You can try as a workaround setting the Libraries > Use Run-Time Library property of the DLL project to "Multithreaded", which should match what your EXE has for that setting.

View solution in original post

0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,547 Views

This error is probably not related to code inside your application, but rather how you built it or ran it. Did you use the "Intel 64" compiler to build both the DLL and the executable? What is the value of the PATH system environment variable?

One easy way to diagnose this - download Dependency Walker, run it and drag your EXE to its window. See what errors it gives - specifically if it complains about mixing architectures. (If you see an error about MSJAVA.DLL, ignore it.)

0 Kudos
mi-she
Beginner
1,547 Views

I compiled both the .exe and the .dll without changing any settings for the Intel 64 compiler. However, I ran the dependency walker and got

Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.

It appears that the MSJAVA.DLL (ignore it, like you said) and DEVMGR.DLL modules could not be found and most of the modules have x86 as the CPU whereas the main program and dll had x64 for the CPU. I have created several other dlls recently without problems, but they did not use the system command. Could this be caused by using the system command? How would you suggest resolving the other errors? Thanks

0 Kudos
Steven_L_Intel1
Employee
1,547 Views

Ignore the first error. It's the second error that is the problem. I am going to guess that the issue is that the PATH environment variable has the Intel Fortran IA32 folder listed before the INTEL64 folder. Try this.

Right click on My Computer, select Properties. Click on Advanced then Environment Variables. Find PATH (or Path) under System Variables and click Edit. This is hard to read because it's a long string in a short text box, but scroll through it to see if there are any folders shown with IA32 in their names. (For example, C:Program FilesIntelCompilerFortran10.1.025IA32Lib) If so, remove them. Semicolons separate entries in this list. Click OK enough times to close the dialog.

Now try Dependency Walker again (open a new instance.)

0 Kudos
mi-she
Beginner
1,547 Views

I didn't find any file with IA32 folder. Here is the path

C:Program FilesIntelMKL10.0.2.019em64tbin;C:Program Files (x86)MiKTeX 2.5miktexbin;%tec360home%bin;%tec100home%bin;%systemroot%system32;%systemroot%;%systemroot%system32wbem;c:program files (x86)quicktimeqtsystem;c:matlabr2007abin;c:matlabr2007abinwin64;c:program filesati technologiesati control panel;C:MATLABR2006bbin;C:MATLABR2006bbinwin32;%IFORT_COMPILER10%EM64TLib

Did I miss something?

0 Kudos
Steven_L_Intel1
Employee
1,548 Views

That looks ok. It's strange that Dependency Walker found many X86 DLLs - it shouldn't have. Something is wrong on your system.

You can try as a workaround setting the Libraries > Use Run-Time Library property of the DLL project to "Multithreaded", which should match what your EXE has for that setting.

0 Kudos
mi-she
Beginner
1,547 Views

The run-time library was " Multithread DLL (/libs:dll /threads) " and I changed it to " Multithreaded." This fixed the problem. Thank you.

0 Kudos
Steven_L_Intel1
Employee
1,547 Views

Well, it made the problem go away, but did not "fix" it. That change causes your DLL to link against the static libraries, so it is not looking for DLLs. I do not understand why, on your system, a mix of x64 and x86 DLLs was being seen.

0 Kudos
Reply