why vscode debug doesn't recognize local #include? - c

I have been stuck on this bug for a few hours now.
I wrote some code in C that uses functions and structs from another C file that I wrote. when I run the code manually (with the makefile I wrote) it runs.
the makefile:
exec: ../LineParser.c main_c_file.c
gcc -g -m32 -Wall -c ../LineParser.c -o LineParser.o
gcc -g -m32 -Wall -c main_c_file.c -o main_c_file.o
gcc -g -m32 -Wall LineParser.o main_c_file.o -o main_c_file
rm LineParser.o main_c_file.o
but when I am trying to debug it I get the error:
/dir1/dir2/task2/main_c_file.c:123: undefined reference to imported_function'
collect2: error: ld returned 1 exit status
Build finished with error(s).
* The terminal process failed to launch (exit code: -1).
I tried
adding -g to the make file.
to first compile the code
and then add its full path to the program tag in the debug configuration file
{
linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "by-gdb",
"request": "launch",
"name": "Launch(gdb)",
"program": "/dir1/dir2/main_c_file",
"cwd": "${workspaceRoot}"
}
]
}
by the way I am runing this code in Linux

Related

Error 2: The system cannot find the file specified. "Cygwin Make"

I have a project with a makefile, linker file and some other c files. Whenever i try to run the make command from my windows. i end up with this error. I am using a cygwin terminal. The project was initially used Linux environment.
process_begin: CreateProcess(NULL, arm-none-eabi-gcc -c -g -Os -I. -fno-common -
ffunction-sections -ffreestanding -fno-builtin -mthumb -mcpu=cortex-m7 -specs=na
no.specs -Wall -Winline -fstack-usage -DSTM32F769xx -mfloat-abi=hard -mfpu=fpv5-
d16 -fno-strict-aliasing -Wno-discarded-qualifiers stm32init.c -o stm32init.o, .
..) failed.
make (e=2): The system cannot find the file specified.
make: *** [makefile:20: stm32init.o] Error 2
Let me know how i can fix this problem.

Debug in VS 2017 when running through task configuration

I have this simple program called main.c:
#include <stdio.h>
int main(){
puts("hi");
puts("bye");
return 0;
}
and this makefile:
run: main.o
gcc main.o -o run
main.o: main.c
gcc -c -g $< -o $#
clean:
rm -f run main.o
Now I want to use it in VS 2017. So I opened the program folder in VS (main.c and the makefile are located there). Then I configured these tasks for it:
{
"version": "0.2.1",
"tasks": [
{
"taskName": "BUILD",
"appliesTo": "/",
"workingDirectory": "${workspaceRoot}",
"command": "make",
"type": "default"
},
{
"taskName": "RUN",
"appliesTo": "/",
"workingDirectory": "${workspaceRoot}",
"command": "run",
"type": "default"
}
]
}
What I tried to do next, is to put break point in the main function and then use the RUN task. I thought VS will stop the running on the break point but that didn't happen and the program run till the end of it.
How can I use the task configuration, so that when I click on RUN - it will stop on the break points that I put?
It's important for me to emphasize that I want to debug the program using the task configuration only and not via other ways that VS have.

Building and debugging a program with makefile

As part of my university studies I learn C programming. I'm using Eclipse Juno IDE.
Here is the problem: I have few .c and .h files, and a makefile made by our course staff. I want to build the project with this makefile. I spent hours searching all over the internet how to build and debug it, but everytime I think I got it an error jumps.
Can someone please explain once and for always how to do this process - build the project with the given makefile, and run it in debug mode so I can debug it?
It is important to mention that sometimes I failed to build the project and got the following message:
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot open output file Assignment2altVersion.exe: Permission denied
However, I managed to build the project several times, but when I tried to run it in debug mode it was stuck either on "Launching: Configuring GDB" or "Launching C/C++ Application".
EDIT:
there are 6 files: SP_Stack.c, SP_Stack.h, SP_Aux.c, SP_Aux., SP_Stack_UnitTest.c, main.c
SP_Aux.c and main.c #include SP_Aux.h.
SP_Stack.c, SP_Aux. and SP_Stack_UnitTest.c #include SP_Stack.h
here's the makefile:
ex2: main.o SP_Aux.o SP_Stack.o
gcc -std=c99 -Wall -Werror -pedantic-errors main.o SP_Aux.o SP_Stack.o -o ex2
Stack_UnitTest: SP_Stack.o SP_Stack_UnitTest.o
gcc -std=c99 -Wall -Werror -pedantic-errors SP_Stack.o SP_Stack_UnitTest.o -o Stack_UnitTest
main.o: main.c SP_Aux.h SP_Stack.h
gcc -std=c99 -Wall -Werror -pedantic-errors -c main.c
SP_Stack.o: SP_Stack.c SP_Stack.h
gcc -std=c99 -Wall -Werror -pedantic-errors -c SP_Stack.c
SP_Stack_UnitTest.o: SP_Stack.h SP_Stack_UnitTest.c
gcc -std=c99 -Wall -Werror -pedantic-errors -c SP_Stack_UnitTest.c
SP_Aux.o: SP_Aux.c SP_Aux.h
gcc -std=c99 -Wall -Werror -pedantic-errors -c SP_Aux.c
clean:
rm -f main.o SP_Aux.o SP_Stack.o SP_Stack_UnitTest.o Stack_UnitTest ex2
the 6 files I mentioned and the makefile are all in the same directory.
I just tried it all over again: went to the right side of the screen to the "make targets" tab. I chose my project and created a target named "makefile" with "make" as build command. then I double clicked it and the project finishe building. when I tried to run it in debug mode it gets stuck on 96% with a message: "Launching: configuring GDB"

Cannot compile a c project in CodeBlocks. Process terminated with status 1

I have a project in C language and it compiles just fine in visual studio without any problem. But for some reasons I need to compile it in CodeBlocks. I can't find a reason why I get this error when I build the project. This is the full build log :
mingw32-gcc.exe -g -W -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_USRDLL -DSERVICE_EXPORTS -DAXIS2_DECLARE_EXPORT -IC:\Tools\axis2c-bin-1.6.0-win32\include -I. -IC:\Tools\axis2c-bin-1.6.0-win32\include -IC:\Tools\axis2c-bin-1.6.0-win32\include\platforms -IE:\dev\CodeBlocks\MinGW -c C:\Tools\axis2c-bin-1.6.0-win32\bin\tools\wsdl2c\src_addToDatabase_CodeBlocks\adb_Person.c -o "Debug Win32\adb_Person.o"
mingw32-gcc.exe -g -W -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_USRDLL -DSERVICE_EXPORTS -DAXIS2_DECLARE_EXPORT -IC:\Tools\axis2c-bin-1.6.0-win32\include -I. -IC:\Tools\axis2c-bin-1.6.0-win32\include -IC:\Tools\axis2c-bin-1.6.0-win32\include\platforms -IE:\dev\CodeBlocks\MinGW -c C:\Tools\axis2c-bin-1.6.0-win32\bin\tools\wsdl2c\src_addToDatabase_CodeBlocks\adb_addTodatabaseMethod.c -o "Debug Win32\adb_addTodatabaseMethod.o"
mingw32-gcc.exe -g -W -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_USRDLL -DSERVICE_EXPORTS -DAXIS2_DECLARE_EXPORT -IC:\Tools\axis2c-bin-1.6.0-win32\include -I. -IC:\Tools\axis2c-bin-1.6.0-win32\include -IC:\Tools\axis2c-bin-1.6.0-win32\include\platforms -IE:\dev\CodeBlocks\MinGW -c C:\Tools\axis2c-bin-1.6.0-win32\bin\tools\wsdl2c\src_addToDatabase_CodeBlocks\adb_addTodatabaseMethodResponse.c -o "Debug Win32\adb_addTodatabaseMethodResponse.o"
mingw32-gcc.exe -g -W -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_USRDLL -DSERVICE_EXPORTS -DAXIS2_DECLARE_EXPORT -IC:\Tools\axis2c-bin-1.6.0-win32\include -I. -IC:\Tools\axis2c-bin-1.6.0-win32\include -IC:\Tools\axis2c-bin-1.6.0-win32\include\platforms -IE:\dev\CodeBlocks\MinGW -c C:\Tools\axis2c-bin-1.6.0-win32\bin\tools\wsdl2c\src_addToDatabase_CodeBlocks\axis2_extension_mapper.c -o "Debug Win32\axis2_extension_mapper.o"
mingw32-gcc.exe -g -W -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_USRDLL -DSERVICE_EXPORTS -DAXIS2_DECLARE_EXPORT -IC:\Tools\axis2c-bin-1.6.0-win32\include -I. -IC:\Tools\axis2c-bin-1.6.0-win32\include -IC:\Tools\axis2c-bin-1.6.0-win32\include\platforms -IE:\dev\CodeBlocks\MinGW -c C:\Tools\axis2c-bin-1.6.0-win32\bin\tools\wsdl2c\src_addToDatabase_CodeBlocks\axis2_stub_AddToDatabaseService.c -o "Debug Win32\axis2_stub_AddToDatabaseService.o"
mingw32-gcc.exe -g -W -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_USRDLL -DSERVICE_EXPORTS -DAXIS2_DECLARE_EXPORT -IC:\Tools\axis2c-bin-1.6.0-win32\include -I. -IC:\Tools\axis2c-bin-1.6.0-win32\include -IC:\Tools\axis2c-bin-1.6.0-win32\include\platforms -IE:\dev\CodeBlocks\MinGW -c C:\Tools\axis2c-bin-1.6.0-win32\bin\tools\wsdl2c\src_addToDatabase_CodeBlocks\main.c -o "Debug Win32\main.o"
mingw32-gcc.exe -g -W -O0 -DWIN32 -D_DEBUG -D_WINDOWS -D_USRDLL -DSERVICE_EXPORTS -DAXIS2_DECLARE_EXPORT -IC:\Tools\axis2c-bin-1.6.0-win32\include -I. -IC:\Tools\axis2c-bin-1.6.0-win32\include -IC:\Tools\axis2c-bin-1.6.0-win32\include\platforms -IE:\dev\CodeBlocks\MinGW -c C:\Tools\axis2c-bin-1.6.0-win32\bin\tools\wsdl2c\src_addToDatabase_CodeBlocks\adb_Message.c -o "Debug Win32\adb_Message.o"
mingw32-g++.exe -LC:\Tools\axis2c-bin-1.6.0-win32\lib -LC:\Tools\axis2c-bin-1.6.0-win32\lib -LE:\dev\CodeBlocks\MinGW\lib -o AddToDatabaseServiceClient.exe "Debug Win32\adb_Person.o" "Debug Win32\adb_addTodatabaseMethod.o" "Debug Win32\adb_addTodatabaseMethodResponse.o" "Debug Win32\axis2_extension_mapper.o" "Debug Win32\axis2_stub_AddToDatabaseService.o" "Debug Win32\main.o" "Debug Win32\adb_Message.o" C:\Tools\axis2c-bin-1.6.0-win32\lib C:\Tools\axis2c-bin-1.6.0-win32\lib\axiom.lib C:\Tools\axis2c-bin-1.6.0-win32\lib\axutil.lib C:\Tools\axis2c-bin-1.6.0-win32\lib\axis2_engine.lib
e:/dev/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: C:\Tools\axis2c-bin-1.6.0-win32\lib: No such file: Permission denied
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 8 seconds)
0 errors, 0 warnings
I'm using CodeBlocks 10.05 and GNU GCC compiler(minGW). the project is an axis2c generated C webservice client.
I put -fPIC in Other options tab under the Compiler settings. then I rebuilt the project. as it was mentioned in CodeBlocks-wiki . I tried to run the application but I got that error again.
I have another question that I posted in This link which is related to this issue. I'd appreciate it if anyone help me.
Do you see that the linker's error message says:
C:\Tools\axis2c-bin-1.6.0-win32\lib: No such file
That is because there is no such file as C:\Tools\axis2c-bin-1.6.0-win32\lib. It is a directory, and you cannot "link a directory", just as you cannot "compile a directory".
We can be sure it is a directory because all the libraries that you are linking are in that directory:
C:\Tools\axis2c-bin-1.6.0-win32\lib\axiom.lib
C:\Tools\axis2c-bin-1.6.0-win32\lib\axutil.lib
C:\Tools\axis2c-bin-1.6.0-win32\lib\axis2_engine.lib
and also because you have specified (twice) that it is a directory that the linker should search to find libraries:
-LC:\Tools\axis2c-bin-1.6.0-win32\lib -LC:\Tools\axis2c-bin-1.6.0-win32\lib
You need to either:
Replace C:\Tools\axis2c-bin-1.6.0-win32\lib in your Link libraries settings with
C:\Tools\axis2c-bin-1.6.0-win32\lib\<name_of_some_missing_library>.lib
or, if there is no missing library (the 3 above are all you need), then:
Delete C:\Tools\axis2c-bin-1.6.0-win32\lib from your Link libraries settings
You can also delete -LC:\Tools\axis2c-bin-1.6.0-win32\lib from the Other linker options
(if that's how you've specified this linker search path), and/or you can delete
C:\Tools\axis2c-bin-1.6.0-win32\lib from Search directories -> Linker (if
that's how you've done it). You are specifying all of the axis libraries by absolute
pathnames, so there is no need to tell the linker where to look for them.
You may have also have produced this duplicated linker search path by specifying it
once in Settings -> Compiler -> Global compiler settings and again in the Linker settings or
Search directories -> Linker of your project. If so, remove it from the global compiler settings.
Those settings are ones that you want to apply to every project that you build with the compiler: that's the significance of Global.
-fPIC has no relevance whatever and you do not require it to build an .exe
I did what #Mike Kinghan said.
plus I searched and found out that the libraries that I'm using are compiled with MSVC++ and cannot be used with MinGW. according to this topic.
I created .def files with reimp
then I modified each stdcall function in .def files (I changed "_name#ordinal" to "name")
then I used dlltool to create .a files.
I linked the .a files to my project.
Everything went fine and I could compile my project. but when I try to run it. I get this error.
The procedure entry point axiom_attribute_create could not be located in the dynamic link library
I have got no idea what to do.

mDNSResponder not compiling out of the box on Maverick

this morning I downloaded the lastest mDNSResponder from the Apple opensource repository. I opened the xCode project (mDNSResponder-544/mDNSMacOSX) and tried to compile, but few files are missing:
#include <CoreFoundation/CFXPCBridge.h> in BonjourEvents.c is not found.
#include <dispatch/private.h> in dns-sd.c is not found (but compiles with GCC, so I'm ok with that)
other errors...
I am running Xcode 5.1 on OSx 10.9.2, with command line tool installed.
I am attaching the output of xcodebuild:
$ xcodebuild
--- xcodebuild: WARNING: The directory /Users/kas/Downloads/mDNSResponder-544/mDNSMacOSX also contains the legacy project 'mDNSResponder.pbproj' - ignoring it and using 'mDNSResponder.xcodeproj'.
=== BUILD TARGET BonjourEvents OF PROJECT mDNSResponder WITH THE DEFAULT CONFIGURATION (Development) ===
Check dependencies
CompileC build/mDNSResponder.build/Development/BonjourEvents.build/Objects-normal/x86_64/BonjourEvents.o BonjourEvents.c normal x86_64 c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/adsada/Downloads/mDNSResponder-544/mDNSMacOSX
export LANG=en_US.US-ASCII
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c -arch x86_64 -fmessage-length=129 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -Wno-trigraphs -fpascal-strings -Os -Werror -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -D__APPLE_USE_RFC_3542=1 -D_DNS_SD_LIBDISPATCH=1 -DAPPLE_OSX_mDNSResponder=1 -D__MigTypeCheck=1 -DmDNSResponderVersion=(Engineering\ Build) -D_LEGACY_NAT_TRAVERSAL_ -D_BUILDING_XCODE_PROJECT_=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -mmacosx-version-min=10.9 -g -Wno-sign-conversion -iquote /Users/askdjkadj/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/BonjourEvents-generated-files.hmap -I/Users/sdaad/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/BonjourEvents-own-target-headers.hmap -I/Users/sadad/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/BonjourEvents-all-target-headers.hmap -iquote /Users/asdsad/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/BonjourEvents-project-headers.hmap -I/Users/asdd/Downloads/mDNSResponder-544/mDNSMacOSX/build/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/asad/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/DerivedSources/x86_64 -I/Users/adssad/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/DerivedSources -W -Wall -Wmissing-prototypes -Wno-four-char-constants -Wno-unknown-pragmas -Wshadow -F/Users/asdd/Downloads/mDNSResponder-544/mDNSMacOSX/build -DUSE_SYSTEMCONFIGURATION_PRIVATE_HEADERS -fwrapv -MMD -MT dependencies -MF /Users/asd/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/Objects-normal/x86_64/BonjourEvents.d --serialize-diagnostics /Users/sad/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/Objects-normal/x86_64/BonjourEvents.dia -c /Users/asd/Downloads/mDNSResponder-544/mDNSMacOSX/BonjourEvents.c -o /Users/ads/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/Objects-normal/x86_64/BonjourEvents.o
/Users/asd/Downloads/mDNSResponder-544/mDNSMacOSX/BonjourEvents.c:19:10: fatal error: 'CoreFoundation/CFXPCBridge.h' file not found
#include <CoreFoundation/CFXPCBridge.h>
^
1 error generated.
2014-04-06 13:10:32.208 xcodebuild[3417:30b] DVTAssertions: Warning in /SourceCache/IDEXcode3ProjectSupport/IDEXcode3ProjectSupport-5067/Xcode3Core/LegacyProjects/Frameworks/DevToolsCore/DevToolsCore/SpecificationTypes/BuiltInSpecifications/Compilers/XCGccMakefileDependencies.m:76
Details: Failed to load dependencies output contents from ``/Users/asd/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/Objects-normal/x86_64/BonjourEvents.d''. Error: Error Domain=NSCocoaErrorDomain Code=260 "The file “BonjourEvents.d” couldn’t be opened because there is no such file." UserInfo=0x7fbacb566c60 {NSFilePath=/Users/asd/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/Objects-normal/x86_64/BonjourEvents.d, NSUnderlyingError=0x7fbacb5364c0 "The operation couldn’t be completed. No such file or directory"}. User info: {
NSFilePath = "/Users/ada/Downloads/mDNSResponder-544/mDNSMacOSX/build/mDNSResponder.build/Development/BonjourEvents.build/Objects-normal/x86_64/BonjourEvents.d";
NSUnderlyingError = "Error Domain=NSPOSIXErrorDomain Code=2 \"The operation couldn\U2019t be completed. No such file or directory\"";
}.
Function: void XCGccMakefileDependenciesParsePathsFromRuleFile(NSString *__strong, void (^__strong)(NSString *__strong))
Thread: <NSThread: 0x7fbacb561070>{name = (null), num = 7}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
** BUILD FAILED **
The following build commands failed:
CompileC build/mDNSResponder.build/Development/BonjourEvents.build/Objects-normal/x86_64/BonjourEvents.o BonjourEvents.c normal x86_64 c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
and indeed locate CFXPCBridge.h returns nothing.
Thanks for your help.

Resources