okay so here's the little piece of code that would be useful in a sudoku program that i'm making...
this function leftover is simply extracting the set minus of two arrays. i don't know if logic's been having any problem but i think its pretty simple clear.
oh, and i'm using dev c++
and this is c++ code, not c

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
	 int all[9]={1,2,3,4,5,6,7,8,9},alf[4]={1,4,7,6},lo[9]; 

/*initialized alf too just to see if lo gets filled with the leftover 6 nos from the all, ie with nos other than 1,4,7,6*/


	 int i=0,j=0,k=0,p=0;




/*so basically lo = all=alf; then i would randomly pick an element from lo to fill the individual cell....ok that all was short story to give some intro to my problem, and what i'm doing here and why*/


	 while(j<9)
	 {i=0;          k=0;
	 while(k<4)
	 {
           if(alf[k]!=all[j])
	   {
	   i++;
	   }
	   k++;
	 }  //end of inner while

if(i==4)
{
		  lo[p]=all[j];  //storing element not already present in leftover array
		  p++;
}
j++;
}//end of outer while

int g=0;

while(g<p)
{
cout<<lo[g]<<endl; //to just see if the other 6 nos are infact coming in the lo, so printing lo
}

getch();
return 0;
}

now the errors am getting are:

cannot find -lobjc
ld returned 1 exit status

in the compile log, this is the detailed thing its displaying:

Compiler: Default compiler
Executing g++.exe...
g++.exe "c:\Users\ronnieaka\Desktop\Dynamic Folder\Projects\st proj\sud\leftover.cpp" -o "c:\Users\ronnieaka\Desktop\Dynamic Folder\Projects\st proj\sud\leftover.exe" -ansi -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -lobjc -g3
C:\Dev-Cpp\Bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lobjc
collect2: ld returned 1 exit status

Execution terminated

Dani AI

Generated

Two separate problems are visible in the thread: a linker problem (the build is being told to link an Objective‑C runtime that the toolchain does not have) and a small runtime/logic bug in the example code that causes the print loop never to end. correctly pointed at the stray Objective‑C link request and pointed to the project parameters where such a flag is normally set.

The linker message "cannot find -lobjc" means the linker was given -lobjc but cannot find the corresponding library file. The correct fix for a pure C++ project is to remove that linker token from the project’s linker flags (project-level parameters or global compiler/linker options), or edit the project file with a text editor and delete -lobjc. Only keep or add that flag if Objective‑C code is actually being built and the matching libobjc for the MinGW toolchain is installed. After changing flags, do a full clean + rebuild to avoid stale objects.

There’s also a logic/runtime bug in the sample: the final while(g < p) loop never increments g, so the program hangs printing the same value. A safer, clearer approach uses STL containers and algorithms (no manual counters or fixed-size raw arrays):

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    std::vector<int> all{1,2,3,4,5,6,7,8,9};
    std::vector<int> alf{1,4,7,6};
    std::vector<int> lo;

    for (int v : all)
        if (std::find(alf.begin(), alf.end(), v) == alf.end())
            lo.push_back(v);

    for (int x : lo)
        std::cout << x << '\n';
}

Additional tips: compile with warnings enabled (-Wall -Wextra) and a modern standard (-std=c++11 or later), replace nonportable pauses (getch()/conio.h) with std::cin.get() if needed, and prefer vectors/algorithms (or std::set_difference on sorted ranges) to avoid off‑by‑one and maintenance issues.

Recommended Answers

All 3 Replies

lobjc is the Objective-C library. You do not need it in C++, so remove it from the list of included libraries and that error should go away. Edward has not used Dev C++ in ages though. You will need to figure out where to make that change. Probably in the project settings somewhere. ;)

yeah but how do i know what to remove, u have seen the header files

now conio.h i seeked out from google and its an extension in borland c++ and one shouldn't include it when working in dev
so instead of clrscr() i used system(cls) with stdlib included but still getting that stupid error

Go to Project -> Project Options

It opens a dialog box, go to parameters, under linker look for -lobjc
When you find it delete it. That parameter was not found by the compiler.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.