Cygwin fails to link a c++ project with sanitizers
I have a c++ project which I try to build with Cygwin (with gcc compiler) in CLion. It compiles successfully, but on the linking stage I get an error:
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lasan
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lubsan
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/main.dir/build.make:106: main.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:158: CMakeFiles/main.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:165: CMakeFiles/main.dir/rule] Error 2
make: *** [Makefile:184: main] Error 2
It seems like the linker fails to find sanitizer libraries, because when I change a line in my CMakeLists.txt from
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined,address,leak -fno-sanitize-recover=all -D_GLIBCXX_DEBUG")
to
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-sanitize-recover=all -D_GLIBCXX_DEBUG")
it builds successfully. The code doesn't matter, the same happens with a "hello world" project.
I would like to use sanitizers in my development, so my question is how do I make it link correctly.
See also questions close to this topic
-
How to return an enum by item index as apposed to value index?
How do I index into an enum via "item index" instead of the "value indexing":
"Value indexing" (not useful to me with what I am doing):
eSerialBauds eBaud = static_cast<eSerialBauds>(1200); // yields eBaud1200
I want "item indexing": ( How to get the following? )
eSerialBauds eBaud = static_cast<eSerialBauds>(3); // to yield eBaud1200
// values (from WinBase.h) #define CBR_110 110 #define CBR_300 300 #define CBR_600 600 #define CBR_1200 1200 #define CBR_2400 2400 enum class eSerialBauds { eBaud110 = CBR_110, eBaud300 = CBR_300, eBaud600 = CBR_600, eBaud1200 = CBR_1200, eBaud2400 = CBR_2400, }
Please note that I am given this enum class from another class. There are many. So I have to work with what is given to me.
I did write a work around method but it would be nice to have a more elegant way of getting the result.
-
I have a problem with a code c++ compiler lex and yacc
and the error of code
yacc
code , conflicts: 9 reduce/reduce , What is the solution to this error?lex
code:%option noyywrap %option yylineno %{ #include<stdio.h> #include<string.h> #include "y.tab.h" FILE *out; %} %% "begin"|"print"|"end"|"while"|"endwhile"|"if"|"else"|"endif"|"read" {fprintf(out,"keyword :%s\n",yytext);} [A-Za-z][A-Za-z0-9_]+ {fprintf(out,"Identifier :%s\n",yytext);return ident;} "+" {fprintf(out,"plus :%s\n",yytext);} ":=" {fprintf(out,"assignsymbol :%s\n",yytext);} ";" {fprintf(out,"semicolon :%s\n",yytext);} [0-9]+ { fprintf(out,"number :%s\n",yytext); return number;} "(" {fprintf(out,"leftpar :%s\n",yytext);} ")" {fprintf(out,"righttpar :%s\n",yytext);} .|[\n] {yylineno++;} %% int main() { yyin=fopen("read.txt","r"); out=fopen("write.txt","w"); yylex(); return 0; }
yacc
code:%{ #include <stdio.h> int yylex(void); void yyerror(char *); %} %start program %token number ident %right '=' %left '+' '-' %left '*' '/' %% program: "begin" stmt_list "end"; stmt_list: stmt ';' | stmt ';' stmt_list ; stmt: assign | if_stmt | while_stmt "read" '(' ident ')' | "print" '(' ident ')' ; assign: ident ":=" expr expr: expr '+' term { $$ = $1 + $3; } | expr '-' term { $$ = $1 - $3; } | term { $$ = $1; } ; term: term '*' factor { $$ = $1 * $3; } | expr '/' term { if($3==0) yyerror([gdivide0پh]); else $$ = $1 / $3; } | factor { $$ = $1; } ; factor: ident { $$ = $1; } | number { $$ = $1; } | '(' expr ')' { $$ = $2; } ; if_stmt: "if" '(' logic_expr ')' "then" stmt_list "endif" | "if" '(' logic_expr ')' "then" stmt_list "else" stmt_list "endif" ; while_stmt: "while" '(' logic_expr ')' stmt_list "endwhile" ; logic_expr: logic_term '>' logic_term |logic_term '<' logic_term |logic_term '>' '=' logic_term |logic_term '<' '=' logic_term |logic_term '<' '>' logic_term |logic_term '=' logic_term { $$ = $1 ; } ; logic_term: number { $$ = $1; } | ident { $$ = $1; } | '(' logic_expr ')' ; %% void yyerror(char *s) { fprintf(stderr, ""At line %d %s "", yylineno, s); } int main(void) { yyparse(); return 0; }
-
I want it to close when it opens the exe file separately
I have two exe files coded in C# and C++. What I want to do is to download and run the exe coded with C++ from C#. When the C++ application is not brought from the C# application, I do not want it to be launched directly from the downloaded folder. How can I do this?
-
Is there a way to inject the Azure DevOps buildId into a Vue.js build?
Right now I am using a version number on my vue app frontend, which I manually write into
package.json
and then get it from there like this:// package.json { ... "version": "1.1.3", ... }
// vue.config.js // ... process.env.VUE_APP_VERSION = require('./package.json').version
// store/index.js state: { // ... appVersion: process.env.VUE_APP_VERSION || '0' },
I was wondering if there is a way to inject an Azure DevOps
buildId
into a Vue build, so that I can display it directly on the web app frontend? -
Azure app service build and deploy failing on GitHub
I just uploaded a very basic Xamarin mobile app to git hub. I used the azure option to set up a service to build and deploy. Unfortunately the GitHub build is failing in both the IOS and Android projects for the same error: Error:
D:\a\MobileApplication\MobileApplication\MobileApplication\MobileApplication\Services\EventMockData.cs(65>,1): error CS1022: Type or namespace definition, or end-of-file expected >[D:\a\MobileApplication\MobileApplication\MobileApplication\MobileApplication\MobileApplication.csproj]
I can't find anything wrong with the EventMockData.cs file. and the whole project builds successfully in my local VS.
using MobileApplication.Models; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace MobileApplication.Services { class EventMockData : IDataStore<Event> { readonly List<Event> events; public EventMockData() { events = new List<Event>() { new Event { id = 1, eventName = "Sunday School", eventContactName = "John", eventContactEmail = "john@test.com", eventContactPhone = 1234567890, eventImageUrl = "https://wwww.dell.com", eventStartDateTime = new DateTime(2021, 04, 30, 13, 00, 00), eventEndDateTime = new DateTime(2021, 04, 30, 20, 00, 00), eventRecurrance = "daily", eventRecurranceInterval = 1, eventRecurrenceDayInterval = ""} }; } public async Task<bool> AddItemAsync(Event item) { events.Add(item); return await Task.FromResult(true); } public async Task<bool> UpdateItemAsync(Event item) { var oldItem = events.Where(e => e.id == item.id).FirstOrDefault(); events.Remove(oldItem); events.Add(item); return await Task.FromResult(true); } public async Task<bool> DeleteItemAsync(int id) { var oldItem = events.Where((Event arg) => arg.id == id).FirstOrDefault(); events.Remove(oldItem); return await Task.FromResult(true); } public async Task<Event> GetItemAsync(int id) { return await Task.FromResult(events.FirstOrDefault(s => s.id == id)); } public async Task<IEnumerable<Event>> GetItemsAsync(bool forceRefresh = false) { return await Task.FromResult(events); } } }
-
VSCode CMake Extension rebuild all project each time
I'm working on a project in C++ configured using CMake.
Each time I build the project, all files are recompiled, which is unbearable considering the time it takes.With Visual Studio Code
I'm trying to use VSCode and the CMake Extension.
TheCMake:Configure
command works well and so does theCMake:Build
command. It takes a lot of time to compile because I use highly templatized header-only libraries like Eigen3, Boost and CGAL, so I need to build a pre-compiled header. It build some librairies too. But it is normal that it takes time for a first compilation.However, if I build the target again (without modifying anything in the code) the compilation is completely redone ! I just want the modified source files or librairies to be re-compiled. Or if a header in the list of pre-compiled headers is modified, only then should the pre-compiled headers be recompiled.
With Visual Studio 2019
I thought that VSCode didn't work with a concept of "project", and therefore had to reconfigure and recompile the whole project every time it was launched.
So I decided to generate a Visual Studio Solution with the CMake-GUI program and use Visual Studio 2019 instead of VSCode.
Now when I build a second time my project, nothing is recompiled and the program is directly lauched. Visual Studio say :========== Build: 0 succeeded, 0 failed, 5 up-to-date, 0 skipped ==========
Wonderful!
Unfortunately not..., because if I modify a file, Visual Studio keeps telling me that everything is up-to-date and my modifications are not taken into account. I need to "Rebuild" the project so that everything will be recompiled, which does not solve my problem as it takes a lot of time.Question
How to recompile only modified source files, librairies or pre-compiled headers (with VS Code, Visual Studio or both) ?
Plaform : Windows 10
Edit 15.04.21
I did some more methodical testing today to find out what the problem might be.
I used a very simple project to do the tests.CMakeList.txt
cmake_minimum_required (VERSION 3.8) project ("HelloCMake") add_executable (HelloCMake "HelloCMake.cpp")
HelloCMake.cpp
#include <iostream> int main() { std::cout << "Hello CMake !" << std::endl; return 0; }
1. With VSCode and CMake Tools Extension
With the CMake Tools Extension, VSCode can configure and build a CMake project. It generate a Visual Studio Solution (
.sln
).- Build the target with CMake Tools Extension which makes VSCode to run the command :
cmake --build <PROJECT_DIR>/build --config Release --target HelloCMake -- /maxcpucount:14
- The entire target is compiled
- I build it again (without changes)
- The target is completely recompiled again
The problem is that the target is completely recompiled, every time. I asked the question directly to the CMake Tools developers. GitHub Issue
2. .sln project generated by CMake (Visual Studio 2019)
- I generated a Visual Studio Solution with CMake and open it.
- I build my project HelloCMake
- I do some modifications in source file
- I build the project again, but Visual Studio never takes my modifications into account. The builds are always "up-to-date".
The problem is that Visual Studio does not take my changes into account. I have to rebuild the project, which takes too much time.
3. Directly open CMake project with Visual Studio 2019 (Ninja)
If you open a CMakeList.txt with Visual Studio 2019, it is not a Visual Studio Solution that is generated but a Ninja one.
It seems that this way the compilation works correctly !
According to this research, it is the CMake Tools Extension for VSCode as well as the Visual Studio Solution that cause problems.
I can't figure out why such a simple project doesn't compile properly with a Visual Studio Solution generated by CMake.
- Build the target with CMake Tools Extension which makes VSCode to run the command :
-
Is cygwin possible to install epoll.h on win10?
I compile a linux network project with cygwin32 on win10.
The reason for doing this is that I can use comfortable IDE coding envrionment and donot need switch to linux environment to do real-time compilation.
Cygwin shows non-found file error.fatal error: sys/epoll.h: No such file or directory 6 | #include <sys/epoll.h>
Does this mean epoll is something only available in the linux 2.6 kernel? Cygwin has most but not all linux feature?
-
Start cmd.exe from cygwin shell with original Windows environment variables?
I cannot use vcvarsall.bat from cygwin because cygwin overwrites environment variables (like PATH) and then the environment in cmd.exe, which is inherited from the cygwin BASH environment, finds the wrong cmake.exe.
Is there any pre-defined way to do this? Maybe without having to resort to opening a new shell window? Currently, I'm rewriting and stripping the entire PATH string. But now I have another issue: TEMP points to the wrong directory. I could just change that manually, but I really want it to adhere to original Windows behaviour.
-
No Gearman worker available
Hello everyone I am having issues starting an Gearman woker in Windows I keep on getting this error.
500 | Internal Server Error | Net_Gearman_Exception No Gearman worker available that can handle the job arFileImportJob.
I have the Gearmand Server running in cygwin64, and I already installed PECL with gearman.
Thanks for the help
-
Why is clang reporting an undefined symbol for an extern variable referenced in a static library
I witnessed this error which is reproducible in
AppleClang 12.0.0
but not withgcc 7.5.0
. The issue is that I have anextern
variable defined in a static library which a different static library wants to use. The linker states that the symbol for the variable is undefined. I tried to come up with an as minimal as possible repro:externs.h
extern int A;
a.c
int A;
b.h
void bar();
b.c
#include "externs.h" #include <stdio.h> void bar() { A = 100; printf("%d\n", A); }
main.c
#include "b.h" int main() { bar(); }
makefile
liba.a: a.c gcc -c a.c -o a.o ar crs liba.a a.o libb.a: b.c gcc -c b.c -o b.o ar crs libb.a b.o program: main.c liba.a libb.a gcc main.c -L. -lb -la -o program
On Linux, this program compiles, links and runs without issue. On macOS (where
gcc
isAppleClang
) I get the following output :gcc -c a.c -o a.o ar crs liba.a a.o warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: liba.a the table of contents is empty (no object file members in the library define global symbols) gcc -c b.c -o b.o ar crs libb.a b.o gcc main.c -L. -lb -la -o program Undefined symbols for architecture x86_64: "_A", referenced from: _bar in libb.a(b.o) ld: symbol(s) not found for architecture x86_64
AFAICT, the warning is a red herring. If I add a dummy function to
a.c
, the warning doesn't show. Further, if I inspectliba.a
withnm
I get the following output:liba.a(a.o): 0000000000000004 C _A
If I do add a dummy function
foo
(which doesn't even refer toA
) toliba.a
and invoke it frommain.c
, the linking issue gets magically resolved. It's as if if and only ifmain.o
is dependent on a symbol inliba.a
, then all the symbols ofliba.a
become available to anything that may be dependent on them. -
mingw32 gcc importing symbols from wrong library
I'm trying to build a CPython extensions on Linux for Windows, using mingw64's cross-compiler.
I've copied the include folder and lib file from a Windows distributions and compiled with the following command:
x86_64-w64-mingw32-gcc extension.c -o extension.pyd -I py_38_win/include -L py_38_win -shared -fPIC -static -lpython38
The compilation succeeds, but the DLL created, is trying to import all
kernel32.dll
symbols frompython38.dll
, which of course, doesn't have them, so it obviously fails to load.- Any idea why this is happening?
python38.lib
isn't even exporting these symbols - Any ideas on how I can troubleshoot this? Is there a linker flag to log the symbol resolution and maybe shed some light on this?
extension.c:
#include <Python.h> static PyObject * f(PyObject *self, PyObject *args) { printf("I am the extension\n"); Py_RETURN_NONE; } static PyMethodDef _module_methods[] = { {"f", f, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; static struct PyModuleDef _mymodule = { PyModuleDef_HEAD_INIT, "extension", "an extension module", -1, _module_methods, NULL, NULL, NULL, NULL }; PyMODINIT_FUNC PyInit_extension(void) { PyObject *m = PyModule_Create(&_mymodule); if (!m) return NULL; return m; }
Here's the output of
dumpbin /imports
for the generated DLL:C:\>dumpbin.exe /imports extension.pyd Microsoft (R) COFF/PE Dumper Version 14.28.29335.0 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file extension.pyd File Type: DLL Section contains the following imports: python38.dll 693891C0 Import Address Table 69389070 Import Name Table 0 time date stamp 0 Index of first forwarder reference 5FD _Py_NoneStruct 1FD PyModule_Create2 11B DeleteCriticalSection 13F EnterCriticalSection 228 GetCurrentProcess 229 GetCurrentProcessId 22D GetCurrentThreadId 276 GetLastError 301 GetSystemTimeAsFileTime 31F GetTickCount 37C InitializeCriticalSection 3D8 LeaveCriticalSection 46B QueryPerformanceCounter 4C6 RtlAddFunctionTable 4C7 RtlCaptureContext 4CE RtlLookupFunctionEntry 4D5 RtlVirtualUnwind 572 SetUnhandledExceptionFilter 582 Sleep 591 TerminateProcess 5A5 TlsGetValue 5B3 UnhandledExceptionFilter 5D4 VirtualProtect 5D6 VirtualQuery KERNEL32.dll 693891D0 Import Address Table 69389080 Import Name Table 0 time date stamp 0 Index of first forwarder reference 11B DeleteCriticalSection 13F EnterCriticalSection 228 GetCurrentProcess 229 GetCurrentProcessId 22D GetCurrentThreadId 276 GetLastError 301 GetSystemTimeAsFileTime 31F GetTickCount 37C InitializeCriticalSection 3D8 LeaveCriticalSection 46B QueryPerformanceCounter 4C6 RtlAddFunctionTable 4C7 RtlCaptureContext 4CE RtlLookupFunctionEntry 4D5 RtlVirtualUnwind 572 SetUnhandledExceptionFilter 582 Sleep 591 TerminateProcess 5A5 TlsGetValue 5B3 UnhandledExceptionFilter 5D4 VirtualProtect 5D6 VirtualQuery msvcrt.dll 69389288 Import Address Table 69389138 Import Name Table 0 time date stamp 0 Index of first forwarder reference 54 __iob_func 79 _amsg_exit 11E _initterm 184 _lock 2CB _unlock 386 abort 397 calloc 3BE free 3CA fwrite 40D puts 414 realloc 41E signal 433 strlen 436 strncmp 455 vfprintf Summary 1000 .CRT 1000 .bss 1000 .data 3000 .debug_abbrev 1000 .debug_aranges 1000 .debug_frame 35000 .debug_info 3000 .debug_line 4000 .debug_loc 1000 .debug_ranges 1000 .debug_str 1000 .edata 1000 .idata 1000 .pdata 1000 .rdata 1000 .reloc 2000 .text 1000 .tls 1000 .xdata
P.S. It works fine when I compile and run it on Linux:
$ gcc -I /usr/include/python3.8 extension.c -o extension.so -shared -fPIC $ python -c "import extension;extension.f()" I am the extension
- Any idea why this is happening?
-
Recipe for target rule and all C++ CLion Windows one file
I am trying to run an SFML program in CLion. I keep getting an error:
"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" --build C:\Users\filip\CLionProjects\SFML_try1\cmake-build-debug --target SFML_try1 -- -j 6 mingw32-make.exe[3]: *** No rule to make target '/SFML/lib/sfml-system-d.lib', needed by 'SFML_try1.exe'. Stop. mingw32-make.exe[2]: *** [CMakeFiles/SFML_try1.dir/all] Error 2 mingw32-make.exe[1]: *** [CMakeFiles/SFML_try1.dir/rule] Error 2 mingw32-make.exe: *** [SFML_try1] Error 2 CMakeFiles\Makefile2:94: recipe for target 'CMakeFiles/SFML_try1.dir/all' failed CMakeFiles\Makefile2:101: recipe for target 'CMakeFiles/SFML_try1.dir/rule' failed Makefile:137: recipe for target 'SFML_try1' failed
I don't know anything about CMake. I use Windows, CLion, MinGW32, SFML. I don't even know where to look to fix this problem so this is why I don't post any code.
-
SFML Error 1 2 2, CMake failed build windows CLion
I've been trying to set up a new SFML project and i always struggle with importing libraries. I thought that everything is fine but the errors say otherwise. Anyway, heres the code and error message:
vvvv CMake vvvv
cmake_minimum_required(VERSION 3.17) project(SFML_try1) set(CMAKE_CXX_STANDARD 14) add_executable(SFML_try1 main.cpp) include_directories(C:/SFML/include) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules") find_package(SFML REQUIRED system window graphics) if(SFML_FOUND) include_directories(${SFML_INCLUDE_DIR}) target_link_libraries(SFML_try1 ${SFML_LIBRARIES}) endif() file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}) if(WIN32) file(GLOB BINARY_DEP_DLLS "${SFML_INCLUDE_DIR}/../bin/*.dll") file(COPY ${BINARY_DEP_DLLS} DESTINATION ${CMAKE_BINARY_DIR}) endif()
vvvv main.cpp vvvv
#include <iostream> #include <SFML/Graphics.hpp> #include <SFML/System.hpp> #include <SFML/Window.hpp> using namespace sf; int main() { RenderWindow window(VideoMode(640, 480), "screen", Style::Titlebar | Style::Close); Event ev; while(window.isOpen()) { while(window.pollEvent(ev)) { switch(ev.type) { case Event::Closed: window.close(); break; case Event::KeyPressed: if(ev.key.code == Keyboard::Escape) window.close(); break; default: break; } } window.clear(); window.display(); } return 0; }
vvvv error message vvvv
"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" --build C:\Users\filip\CLionProjects\SFML_try1\cmake-build-debug --target SFML_try1 -- -j 6 mingw32-make.exe[3]: *** No rule to make target '/SFML/lib/sfml-system-d.lib', needed by 'SFML_try1.exe'. Stop. mingw32-make.exe[2]: *** [CMakeFiles/SFML_try1.dir/all] Error 2 mingw32-make.exe[1]: *** [CMakeFiles/SFML_try1.dir/rule] Error 2 mingw32-make.exe: *** [SFML_try1] Error 2 CMakeFiles\Makefile2:94: recipe for target 'CMakeFiles/SFML_try1.dir/all' failed CMakeFiles\Makefile2:101: recipe for target 'CMakeFiles/SFML_try1.dir/rule' failed Makefile:137: recipe for target 'SFML_try1' failed
FindSFML.cmake is located inside cmake_modules in SFML_try1 folder
I use minGW toolchain located on C drive
main SFML folder is located on C drive
I use CLion which comes with CMake pre-installed
-
CLion run and makefile showing different results
I have this C++ program in Clion, however, I need to create a makefile for it to be run on text editors and not IDEs, it is for a university, they do not use IDEs.
When I run my program trough the run button on CLion, it works perfectly but when I run it trough the makefile, it displays multiple errors that don't even make sense.
When is the issue occurring from? Please tell me if you need more information or images.
Project structure:
Errors with makefile:
Run without the makefile:
Makefile:
OBJS = main.o HastTable.o Book.o SOURCE = main.cpp HastTable.cpp Book.cpp HEADER = HashTable.h Book.h OUT = book CC = g++ FLAGS = -g -c -Wall -Wextra all: $(OBJS) $(CC) -g $(OBJS) -o $(OUT) $(LFLAGS) main.o: main.cpp $(CC) $(FLAGS) main.cpp HastTable.o: HastTable.cpp $(CC) $(FLAGS) HastTable.cpp Book.o: Book.cpp $(CC) $(FLAGS) Book.cpp clean: rm -f $(OBJS) $(OUT)